mcp
The Multichat MCP Server project focuses on using the Model Context Protocol (MCP) to enable communication with multiple unichat-based MCP servers. By doing so, it aims to enhance its querying capabilities with different language models for more comprehensive results.
Multichat MCP Server
Project Overview
This project is part of a larger effort to refactor a FiveM resource, aiming for a more robust and maintainable codebase. We are leveraging the Model Context Protocol (MCP) to extend the resource's capabilities by integrating with external services and APIs.
The multichat-mcp
server specifically focuses on enabling communication with multiple unichat-based MCP servers simultaneously. This allows us to query different language models and combine their responses, potentially leading to more comprehensive and nuanced results. It acts as a standard MCP server, exposing a multichat
tool that the host (Roo/Cline) can use. The multichat-mcp
server then manages the client connections to the other unichat servers.
Current Issue
We were facing an issue with making cross-server MCP calls. The initial goal was to use the multichat-mcp
server to directly call the unichat
tool on other MCP servers, specifically Lacayo 1
and openrouter-chat
. However, these calls were consistently returning a "Method not found" error (-32601).
Direct calls to the unichat
tools on Lacayo 1
and openrouter-chat
using the use_mcp_tool
command do work correctly. This initially suggested the problem was within multichat-mcp
's cross-server communication. However, after extensive troubleshooting and research, we discovered that MCP does not support direct server-to-server communication. The host (Roo/Cline) is responsible for coordinating all communication between servers.
Troubleshooting Steps and Approaches Tried
We have taken the following steps to diagnose and resolve the "Method not found" error, exploring various approaches:
-
Verified MCP Server Configurations: We carefully reviewed the
cline_mcp_settings.json
file to ensure that all servers (multichat
,Lacayo 1
, andopenrouter-chat
) are correctly configured, with the correct commands, arguments, and environment variables. -
Checked JSON-RPC Request Formats: We consulted the MCP documentation and examples to ensure that the JSON-RPC requests sent by
multichat-mcp
were correctly formatted, including themethod
,params
, andid
fields. -
Tested Direct Calls: We confirmed that direct calls to the
unichat
tools onLacayo 1
andopenrouter-chat
usinguse_mcp_tool
work as expected. This isolated the issue to the cross-server communication attempts withinmultichat-mcp
. -
Consulted Documentation via Perplexity: We used the Perplexity MCP server extensively to search for relevant MCP documentation, examples, and troubleshooting tips. We specifically searched for:
- "Model Context Protocol (MCP) cross-server communication best practices. How to make requests between MCP servers, server discovery, and client connection management. Focus on official documentation and examples."
- "Model Context Protocol (MCP) client connection handling and authentication. How to properly establish and verify connections between clients and servers in MCP. Focus on official documentation and TypeScript SDK examples."
- "MCP (Model Context Protocol) exact method names for tool execution. Looking for real-world examples of tool/call usage, JSON-RPC method names, and successful client-server interactions in the TypeScript SDK. Focus on GitHub issues and discussions about method naming."
- "Model Context Protocol (MCP) implementations on GitHub, focusing on server-to-server communication and cross-server request handling. Look for TypeScript/JavaScript examples from the last year. Include request routing and message passing patterns."
These searches helped us understand the core principles of MCP, the correct method names (
tools/list
andtools/call
), and the client-host-server architecture. We learned that direct server-to-server communication is not supported. -
Modified Server Code (Multiple Iterations): We iteratively modified the
multichat-mcp
server code (src/index.ts
andsrc/server.ts
) to try different approaches, including:-
Incorrect Approaches (Discarded):
- Attempting direct server-to-server calls using raw JSON-RPC requests and stdio manipulation. This was based on a misunderstanding of the MCP architecture.
- Creating multiple
Client
instances within a loop, each attempting to connect to a different server. This is incorrect as each client should connect to a single server. - Trying to use a custom
mcp_instructions
response type to instruct the host to make calls. MCP does not support custom message types for cross-server communication. - Using incorrect method names like
tool/call
(singular) instead oftools/call
(plural). - Attempting to use
rpc.discover
andmcp.tools.list
which are not standard MCP methods. - Trying to use a
tool/route
notification, which is not a standard MCP method.
-
Correct Approach (Current Implementation):
- Creating a single
Client
instance per target server (Lacayo 1, openrouter-chat) and storing them in aMap
. - Using the
StdioClientTransport
to spawn theunichat-ts-mcp-server
as a subprocess. This is necessary becausemultichat-mcp
needs to act as a client to the unichat servers. - Using the
client.listTools()
method to verify the connection and discover available tools. - Using the
client.request()
method with the correcttools/call
method name and parameters, following the standard JSON-RPC 2.0 format. - Using the
client.connect()
and handling the transport correctly. - Properly initializing the client with capabilities.
- Using Zod schema validation to ensure the request and response formats are correct.
- Ensuring the necessary dependencies are installed (
package.json
) and the code is correctly built (tsconfig.json
andnpm run build
).
- Creating a single
-
Current Status
The multichat-mcp
server is currently still returning "Method not found" errors. We are still debugging the issue, but we have made significant progress in understanding the correct MCP architecture and implementation patterns. We are now using the correct client-server communication model, but there may still be subtle issues with our request formatting or server configuration.
Files Involved:
src/server.ts
: The main server implementation.src/index.ts
: The server entry point.package.json
: Dependencies and build scripts.tsconfig.json
: TypeScript configuration.../../../../../../Users/kurror/AppData/Roaming/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json
: MCP server configuration file.
Installation
Prerequisites:
- Node.js and npm installed on your system.
Steps:
-
Navigate to the MCP servers directory:
cd C:\\Users\\kurror\\AppData\\Roaming\\Roo-Code\\MCP
-
Clone or create the
multichat-mcp
directory. -
Place the server files (
package.json
,tsconfig.json
,src/index.ts
,src/server.ts
) inside themultichat-mcp
directory. -
Install the dependencies:
npm install
-
Build the TypeScript code:
npm run build
Configuration
To enable the multichat-mcp
server, you need to add its configuration to the cline_mcp_settings.json
file, located at C:\\Users\\kurror\\AppData\\Roaming\\Code\\User\\globalStorage\\rooveterinaryinc.roo-cline\\settings\\cline_mcp_settings.json
.
Add the following entry to the mcpServers
object:
{
"mcpServers": {
"multichat": {
"command": "node",
"args": [
"C:\\Users\\kurror\\AppData\\Roaming\\Roo-Code\\MCP\\multichat-mcp\\build\\index.js"
],
"env": {}
}
}
}
Usage (Testing)
You can test the multichat-mcp
server using the use_mcp_tool
command in your Cline environment.
multichat
tool:
To send messages to multiple unichat servers and save their responses, use the following format:
<use_mcp_tool>
<server_name>multichat</server_name>
<tool_name>multichat</tool_name>
<arguments>
{
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "What is your opinion about async programming?"
}
],
"servers": ["Lacayo 1", "openrouter-chat"],
"outputDir": "test_output"
}
</arguments>
</use_mcp_tool>
messages
: An array of messages to send to each server. The format follows the standard unichat message format (array of objects withrole
andcontent
).servers
: An array of the names of the unichat servers to call (e.g.,"Lacayo 1"
,"openrouter-chat"
).outputDir
: The directory name (within the MCP server's working directory) where the responses will be saved. Important: The responses are not currently being saved correctly due to the "Method not found" error.
read_response
tool:
To read a saved response file (once the server is functioning correctly), use:
<use_mcp_tool>
<server_name>multichat</server_name>
<tool_name>read_response</tool_name>
<arguments>
{
"outputDir": "test_output",
"server": "Lacayo 1"
}
</arguments>
</use_mcp_tool>
outputDir
: The directory where responses are saved.server
: The name of the server whose response you want to read.
Important Notes for Testing:
- Ensure that the
Lacayo 1
andopenrouter-chat
servers are running and correctly configured incline_mcp_settings.json
. - After making code changes to
multichat-mcp
, you must runnpm run build
in themultichat-mcp
directory to compile the TypeScript code. - The MCP host (Roo/Cline) automatically restarts servers when the configuration file changes, but it may be necessary to manually restart if you encounter issues.
Using Perplexity and Unichat
-
Perplexity: You can use the Perplexity MCP server to research and gather information related to MCP, FiveM development, and any other technical topics. This can be helpful for finding documentation, examples, and solutions to problems.
-
Unichat Servers: The
Lacayo 1
andopenrouter-chat
servers provide access to language models through theunichat
tool. You can use these servers for general coding assistance, debugging, and generating code snippets. You can test them directly usinguse_mcp_tool
to ensure they are functioning correctly.
Updated Usage and Troubleshooting (Corrected)
The original documentation and troubleshooting steps described an incorrect approach for cross-server communication. This section provides the corrected usage instructions and addresses the timeout issues we encountered.
Dependencies
@modelcontextprotocol/sdk
: Provides the core functionality for building MCP servers and clients.zod
: Used for schema validation and type safety.fs/promises
,path
,url
,crypto
: Node.js built-in modules for file system operations, path manipulation, URL parsing, and cryptographic functions.
multichat
tool (Corrected Usage)
The multichat
tool is designed to send the same message to multiple unichat servers and collect their responses. It does not facilitate direct server-to-server communication. The correct way to use it is as follows:
Important: The multichat
server and the unichat
servers it communicates with must be running in separate terminal windows.
-
Start the unichat servers: Open separate terminal windows for each unichat server you want to use (e.g., "Lacayo 1", "openrouter-chat"). In each terminal, navigate to the unichat server directory and run:
cd C:\Users\kurror\AppData\Roaming\Roo-Code\MCP\unichat-ts-mcp-server $env:UNICHAT_MODEL="gpt-4o" # Or your desired model $env:UNICHAT_API_KEY="your_api_key" # Replace with your actual API key node ./build/index.js
-
Start the multichat server: In a separate terminal window, navigate to the
multichat-mcp
directory and run:cd C:\Users\kurror\AppData\Roaming\Roo-Code\MCP\multichat-mcp node ./build/index.js
-
Send the request: In a third terminal window, navigate to the
multichat-mcp
directory and create arequest.json
file with the request content. Then, send the request using PowerShell:cd C:\Users\kurror\AppData\Roaming\Roo-Code\MCP\multichat-mcp $request = @{ jsonrpc = "2.0" id = 1 method = "tools/call" params = @{ name = "multichat" arguments = @{ messages = @( @{role = "system"; content = "You are a helpful assistant."}, @{role = "user"; content = "Hello, world!"} ) servers = @("Lacayo 1", "openrouter-chat") outputDir = "my-test-output" } } } | ConvertTo-Json -Depth 10 $request | Out-File -FilePath "request.json" -Encoding utf8 Get-Content "request.json" | node ./build/index.js
This will create a directory
responses/my-test-output
within themultichat-mcp
directory, containing the responses from each server (e.g.,Lacayo 1.json
,openrouter-chat.json
) and a_session.json
file to track the session. If a server fails to respond, an error file (e.g.,Lacayo 1_error.json
) will be created instead.
read_response
tool (Corrected Usage)
The read_response
tool reads a saved response file generated by a previous multichat
call.
Example Request (within Roo):
<use_mcp_tool>
<server_name>multichat</server_name>
<tool_name>read_response</tool_name>
<arguments>
{
"outputDir": "my-test-output",
"server": "Lacayo 1"
}
</arguments>
</use_mcp_tool>
Important: The outputDir
is relative to the multichat-mcp/responses
directory. The tool expects to find a subdirectory within responses
that matches the outputDir
value. Inside that subdirectory, it looks for either a <server>.json
file (for successful responses) or a <server>_error.json
file (for errors).
Troubleshooting (Updated)
- Timeouts: The primary cause of timeouts was the incorrect assumption that
multichat
could directly call other servers. The corrected usage, with all servers running in separate terminals, addresses this. Ensure all unichat servers are running before sending themultichat
request. - Invalid session directory: This error occurs when
read_response
cannot find the specifiedoutputDir
within themultichat-mcp/responses
directory. Double-check theoutputDir
value and ensure that themultichat
command was run successfully and created the output directory. - No response files created: If no files are created in the
responses
directory, even after following the corrected usage, there might be an issue with file system permissions or a silent error within themultichat
server's response handling. Check the server logs for any error messages. It's also crucial to verify that the unichat servers you are targeting are running and responding correctly. You can test them individually usinguse_mcp_tool
with theunichat
tool.
The errors were:
- Incorrect usage of
setRequestHandler
: I was passing the method name and schema separately, instead of including the method name within the schema. - Incorrect parameter access:
request.params
was not correctly typed due to the schema issue. - Incorrect response schema in
client.request
: I was usingz.any()
, which is not compatible withRequestOptions
.
The fixes are:
- Define
ForwardRequestSchema
correctly: Include themethod
field withz.literal("mcp.forward")
. - Use
setRequestHandler
correctly: Pass only the schema and the handler function. - Access parameters correctly: Use
request.params
after parsing with the schema. - Use
z.unknown()
in the client.request call.