Skip to main content
Glama
flamekk

MCP Streamable HTTP Demo

by flamekk

TP5 MCP 可流式 HTTP 演示

本项目旨在重现以下演示目标:

  • 提供两个工具的 MCP 服务器。

  • 使用 @modelcontextprotocol/inspector 进行测试。

  • 使用通过可流式 HTTP 连接 MCP 的 LangChain/LangGraph 兼容智能体。

  • 使用通过可流式 HTTP 连接 MCP 的 n8n AI 智能体设置。

重要安全提示

提示词中粘贴的 OpenAI 密钥已在聊天中泄露。在运行智能体之前,请撤销该密钥并创建一个新密钥。将新密钥放入 .env 文件中;请勿将其提交到版本控制系统。

Related MCP server: SampleMCP

设置

Copy-Item .env.example .env
npm install

编辑 .env 并设置:

OPENAI_API_KEY=your_new_key

启动 MCP 服务器

npm run server

MCP 端点为:

http://127.0.0.1:3000/mcp

健康检查端点为:

http://127.0.0.1:3000/health

使用 MCP Inspector 进行测试

在一个终端中,保持服务器运行:

npm run server

在另一个终端中,使用 Inspector CLI 列出工具:

npm run inspector:list-tools

在 Windows 上,当前的 Inspector CLI 可能会打印正确的 JSON 响应,然后以 Node/libuv 断言错误退出。如果您看到包含 calculate 和 text_stats 的 tools JSON,则说明 MCP 调用本身已成功。

使用 Inspector CLI 调用工具:

npx --yes @modelcontextprotocol/inspector --cli http://127.0.0.1:3000/mcp --transport http --method tools/call --tool-name calculate --tool-arg operation=add --tool-arg "numbers=[2,3,4]"

您也可以打开 Inspector UI:

npm run inspector

然后选择:

Transport: Streamable HTTP
URL: http://127.0.0.1:3000/mcp

本地冒烟测试

npm run smoke

这将列出 MCP 工具并调用 calculate。

LangChain 智能体

确保服务器正在运行且 .env 包含有效的已轮换 OPENAI_API_KEY。

npm run agent

自定义提示词:

npm run agent -- "Calcule 42 / 6 puis analyse le texte: Bonjour depuis MCP."

n8n 智能体

请遵循 docs/n8n-agent.md。

n8n MCP 客户端工具配置如下:

Endpoint: http://127.0.0.1:3000/mcp
Server Transport: HTTP Streamable
Authentication: None
Tools to Include: All

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    A Python-based MCP server demonstrating basic math and text tools, supporting both SSE and STDIO transports for integration with AI assistants like Cline in VS Code.
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides math and weather tools accessible via LangGraph agent using MCP protocol with stdio and streamable HTTP transports.
    1
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    A calculator MCP server providing add and subtract tools, along with file resources and a code review prompt, supporting in-memory, HTTP, and STDIO transports. It also includes a LangGraph ReAct agent example that uses the tools.
    -