Start xMCP server on app startup - #7
Conversation
Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This pull request activates the xMCP (Model Context Protocol) server by calling its start() method during application initialization. Previously, the server was instantiated but never started, leaving the tool interface inactive. The PR also includes a minor typo fix in the README.
Changes:
- Added
await mcpServer.start()to actually start the MCP server transport layer and begin listening for tool requests - Fixed a double-space typo in README.md
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/index.ts | Added the missing mcpServer.start() call to activate the MCP server's stdio transport during app initialization |
| README.md | Fixed spacing typo (double space between words) |
| // Initialize MCP server (runs in background) | ||
| console.log('🌐 Initializing xMCP server...'); | ||
| const mcpServer = new XMCPServer(config.xApiConfig); | ||
| await mcpServer.start(); |
There was a problem hiding this comment.
The MCP server is started but there's no corresponding cleanup in the graceful shutdown handler. The setupGracefulShutdown function only stops the agent but doesn't close the MCP server connection. This could lead to unclosed resources when the application is terminated.
Consider adding a stop/close method to XMCPServer and calling it during shutdown, similar to how agent.stop() is called.
| // Initialize MCP server (runs in background) | ||
| console.log('🌐 Initializing xMCP server...'); | ||
| const mcpServer = new XMCPServer(config.xApiConfig); | ||
| await mcpServer.start(); |
There was a problem hiding this comment.
The MCP server uses StdioServerTransport which communicates via stdin/stdout. However, the application also uses console.log extensively throughout the agent's operation, which writes to stdout. This creates a conflict where console output will interfere with MCP protocol messages if an external client tries to communicate with the server via stdio.
Consider either:
- Using console.error() for all status logging to keep stdout clear for MCP protocol messages
- Using a different transport mechanism for the MCP server (e.g., HTTP, WebSocket) if stdio communication is not the intended use case
- Documenting that the MCP server should only be used in a separate process without agent logging
The xMCP server is intended to expose standardized X API tools (mentions, threads, search, replies) for autonomous agents via Model Context Protocol. The current startup path initialized the server but did not begin listening, leaving the tool interface inactive.
Example:
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.