// Module included in the following assemblies:
//
// * ai_applications/mcp_server/mcp-server-overview.adoc

:_mod-docs-content-type: PROCEDURE
[id="ai-app-mcp-server-configure-gateway_{context}"]
= Configure the MCP gateway

[role="_abstract"]
To install the Model Context Protocol (MCP) server for Red Hat {product-title} feature, configure the MCP gateway by creating HTTPRoute and MCPServerRegistration resources.

.Prerequisites

* Access to OpenShift console with admin rights.
* The MCP server Helm chart is installed.
* MCP-compatible client connected.
* MCP gateway is installed and verified.

.Procedure

. Create the HTTPRoute for the MCP server by running the following command:
+
[source,terminal]
----
$ oc apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: mcp-api-key-server-route
  namespace: openshift-mcp-server
spec:
  parentRefs:
  - group: gateway.networking.k8s.io
    kind: Gateway
    name: mcp-gateway
    namespace: gateway-system
    sectionName: mcp
  hostnames:
  - ${MCP_SERVER_HOST}
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /mcp
    backendRefs:
    - name: openshift-mcp-server
      port: 8080
EOF
----
+
Where `${MCP_SERVER_HOST}` is the hostname you configured during Helm installation.
+
This HTTPRoute enables the MCP gateway to route traffic to your MCP server instance and is referenced in the MCPServerRegistration resource.

. Create an MCP server Registration Resource by running the following command:
+
[source,terminal]
----
$ oc apply -f - <<EOF
apiVersion: mcp.kuadrant.io/v1alpha1
kind: MCPServerRegistration
metadata:
  name: my-mcp-server-reg
  namespace: openshift-mcp-server
spec:
  toolPrefix: "openshift_"
  targetRef:
    group: "gateway.networking.k8s.io"
    kind: "HTTPRoute"
    name: "mcp-api-key-server-route"
    namespace: openshift-mcp-server
EOF
----
* `metadata.name`: Provide a name for the MCP server registration object.

* `metadata.namespace`: The namespace for the MCP server, which is `openshift-mcp-server`.

* `spec.targetRef.name`:  The name of your MCP server HTTPRoute. You can find this by running the command: `oc get httproute -n openshift-mcp-server`.

* `spec.targetRef.namespace`: The namespace for the MCP server HTTPRoute, which is `openshift-mcp-server`.

. Verify the registration status by running the following commands:
+
[source,terminal]
----
$ oc wait --for=condition=Ready mcpsr/my-mcp-server-reg -n openshift-mcp-server --timeout=120s
$ oc get mcpsr -A
----
+
.Example
+
[source,terminal]
----
NAMESPACE             NAME                PREFIX      TARGET                     PATH   READY   TOOLS   CREDENTIALS   AGE
openshift-mcp-server  my-mcp-server-reg   myserver_   mcp-api-key-server-route   /mcp   True    4                     30s
----
+
The *READY* column should display `True` and the *TOOLS* column should show the number of tools discovered.
+
If the status is not ready, check the MCP server Registration conditions for details by running the following command:
+
[source,terminal]
----
$ oc describe mcpsr my-mcp-server-reg -n openshift-mcp-server
----

. Check the controller logs by running the following command:
+
[source,terminal]
----
$ oc logs -n mcp-system deployment/mcp-gateway-controller
----

. Check the broker logs for tool discovery by running the following command:
+
[source,terminal]
----
$ oc logs -n mcp-system deployment/mcp-gateway-broker-router
----

. Verify that your MCP server tools are available through the MCP gateway:

.. Initialize the MCP session and capture session ID by using -D to dump headers to a file, and then reading the session ID by running the following command:
+
[source,terminal]
----
$ curl -s -D /tmp/mcp_headers -X POST http://mcp-gateway.apps.<cluster-name>.<domain-name>:8001/mcp  \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "test-client", "version": "1.0.0"}}}'
----
+
Where <cluster-name>.<domain-name> is the name and domain of your cluster.

.. Extract the MCP session ID from response headers by running the following commands:
+
[source,terminal]
----
$ SESSION_ID=$(grep -i "mcp-session-id:" /tmp/mcp_headers | cut -d' ' -f2 | tr -d '\r')

$ echo "MCP Session ID: $SESSION_ID"
----

.. List tools by using the session ID in the following command:
+
[source,terminal]
----
$ curl -X POST http://mcp-gateway.apps.<cluster-name>.<domain-name>:8001/mcp \
  -H "Content-Type: application/json" \
  -H "mcp-session-id: $SESSION_ID" \
  -d '{"jsonrpc": "2.0", "id": 2, "method": "tools/list"}'
----
+
Where <cluster-name>.<domain-name> is the name and domain of your cluster.

.. Clean up by running the following command:
+
[source,terminal]
----
$ rm -f /tmp/mcp_headers
----
+
You should now see your MCP server tools in the response, prefixed with your configured toolPrefix (for example, myserver_).
