MCP网关测试工具

用于在本地Kubernetes集群和OKE中部署MCP服务器以测试MCP网关的工具。

  • by Fernando-Benegas
  • 本地部署
  • 更新于
在 GitHub 查看 Fernando-Benegas/mcp

使用说明

Traefik Hub MCP网关测试

本指南的目的是在本地Kubernetes(k8s)集群和OKE(Oracle Kubernetes Engine)中部署一个MCP服务器,以测试MCP网关

本地集群

如何在本地Kubernetes环境中部署Traefik Hub及其所有依赖项以测试MCP网关:

  1. 安装k3s
   curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="--disable traefik" sh -
  1. 从预览环境中获取许可证密钥,并安装最新版本的Traefik Hub
helm repo add --force-update traefik https://traefik.github.io/charts

# Install the Ingress Controller
kubectl create namespace traefik
kubectl create secret generic traefik-hub-license --namespace traefik --from-literal=token=
helm upgrade --install --namespace traefik traefik traefik/traefik \
  --set hub.token=traefik-hub-license \
  --set hub.apimanagement.enabled=true \
  --set hub.platformUrl=https://api-preview.hub.traefik.io/agent --set image.registry=europe-west9-docker.pkg.dev/traefiklabs --set image.repository=traefik-hub/traefik-hub --set image.tag=latest-v3 --set image.pullPolicy=Always
  1. 部署本地 MCP服务器:
kubectl apply -f https://raw.githubusercontent.com/Fernando-Benegas/mcp/refs/heads/main/k8s/mcp-server.yaml
  1. 使用两个终端测试mcp服务器:
  • 第一航站楼
   curl -N http://localhost/mcp?stream=messages
  • 第二航站楼
curl -X POST -H "Content-Type: application/json" -d '{"user":"k8s-tester","text":"Hello again!"}'  http://localhost/mcp

预期在终端1中的输出:

id: 0
data: {"text":"Hello again!","user":"k8s-tester"}
event: message

使用外部MCP服务器

待定(TBD)

客户端和中间件设置

作为客户,我们可以使用 MCP检查员为了实现这一点,可以在Docker容器中运行MCP检查器:

docker run --rm --network host -p 6274:6274 -p 6277:6277 ghcr.io/modelcontextprotocol/inspector:latest

预期输出:

> @modelcontextprotocol/inspector@0.17.0 start
> node client/bin/start.js
Starting MCP inspector...
⚙️ Proxy server listening on localhost:6277
🔑 Session token: ...
   Use this token to authenticate requests or set DANGEROUSLY_OMIT_AUTH=true to disable auth
🚀 MCP Inspector is up and running at:
   http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=...
🌐 Opening browser...
New StreamableHttp connection request
Query parameters: {"url":"http://fernando-traefik-test.duckdns.org/mcp?stream=messages","transportType":"streamable-http"}
Created StreamableHttp client transport
Client <-> Proxy  sessionId: ...

创建中间件:

apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: mcp
  namespace: fernando
spec:
  plugin:
    mcp:
      defaultAction: allow
      resourceMetadata:
#        authorizationServers:
#        - http://lemur-3.cloud-iam.com/auth/realms/localdemo
        resource: http://fernando-traefik-test.duckdns.org
#        resourceDocumentation: https://fernando-traefik-test.duckdns.org/docs
#        scopesSupported:
#        - openid
#        - profile
#        - email
      validation:
        jwt:
#          clientConfig: ...
#          signingSecret: xxx
#          signingSecretBase64Encoded: true
#          publicKey: xxx
#          jwksFile: xxx
#          jwksUrl: xxx
#          ForwardHeaders: true
#          usernameClaim: xxx
#          forwardAuthorization: true
      policies:
        - match: Equals(`mcp.method`, `tools/call`) && Equals(`mcp.params.name`, `get_weather`) && Contains(`jwt.groups`, `developer`)
          action: deny
        - match: Equals(`mcp.method`, `tools/call`) && Prefix(`mcp.params.name`, `read_`)
          action: allow