cowardfxn
MCP Servercowardfxnpublic

mcp trials

用于在一个客户端连接多个MCP服务器的工具,支持OpenAI函数调用和SSE通信。

Repository Info

0
Stars
0
Forks
0
Watchers
0
Issues
Python
Language
-
License

About This Server

用于在一个客户端连接多个MCP服务器的工具,支持OpenAI函数调用和SSE通信。

Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.

Documentation

Connecting to multiple MCP servers in one client

  1. Find tool function meta datas
  2. Construct tools list for OpenAI chat API, e.g.
{
    "type": "function",
    "function": {
        "name": "add_numbers",
        "description": "Adds two numbers.",
        "parameters": {
            "type": "object",
            "properties": {
                "a": {"type": "integer", "description": "First number"},
                "b": {"type": "integer", "description": "Second number"},
            },
            "required": ["a", "b"],
        },
    },
},
  1. Call OpenAI chat/response API, with tools param, and tool_choice optionally
  2. Get response content and tool calls if it exists
msg = response.choices[0].message
resp, tool_calls = msg.content, msg.tool_calls
  1. Extract tool function name and tool function arguments from the tool calls
function_name = tool_call.function.name
function_args = tool_call.function.arguments
if function_args:
    function_args = json.loads(function_args)
  1. Find MCP server session by function name. SSE server URL may require sse path: http://127.0.0.1:8081/sse
async def call_sse_server(self, function_name, arguments=None):
    async with sse_client("http://127.0.0.1:8081/sse") as (sse_read, sse_write):
        async with ClientSession(sse_read, sse_write) as sse_session:
            # Initialize the SSE server connection
            await sse_session.initialize()

            # Call tools and resources on the SSE server
            reverse_result = await sse_session.call_tool(
                function_name, arguments=arguments
            )
            return reverse_result

Initialize server session, cache it, and close it gracefully on exit

  1. Extract tool function execution result from server session.call_tool.
    res = esult.content[0].text

Refactor MCPAgent, connect to MCP servers on class initialization, keep sessions in attribute sessions, keep function name to session mapping, close session on exit

Quick Start

1

Clone the repository

git clone https://github.com/cowardfxn/mcp-trials
2

Install dependencies

cd mcp-trials
npm install
3

Follow the documentation

Check the repository's README.md file for specific installation and usage instructions.

Repository Details

Ownercowardfxn
Repomcp-trials
LanguagePython
License-
Last fetched8/10/2025

Recommended MCP Servers

💬

Discord MCP

Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.

integrationsdiscordchat
🔗

Knit MCP

Connect AI agents to 200+ SaaS applications and automate workflows.

integrationsautomationsaas
🕷️

Apify MCP Server

Deploy and interact with Apify actors for web scraping and data extraction.

apifycrawlerdata
🌐

BrowserStack MCP

BrowserStack MCP Server for automated testing across multiple browsers.

testingqabrowsers

Zapier MCP

A Zapier server that provides automation capabilities for various apps.

zapierautomation