Skip to content

Add MCP (Model Context Protocol) server support#4

Open
webhead2oo9 wants to merge 1 commit intoZeldaFan0225:mainfrom
webhead2oo9:feature/mcp-integration
Open

Add MCP (Model Context Protocol) server support#4
webhead2oo9 wants to merge 1 commit intoZeldaFan0225:mainfrom
webhead2oo9:feature/mcp-integration

Conversation

@webhead2oo9
Copy link
Collaborator

Summary

This PR implements MCP (Model Context Protocol) support for the Discord bot as requested in issue #3.

What's been added

Core MCP Implementation

  • MCPClient: Handles connections to MCP servers via stdio and SSE transports
  • MCPManager: Singleton that manages multiple MCP server connections centrally
  • MCPToolAdapter: Converts MCP tools to the bot's BaseTool interface seamlessly
  • MCPResourceHandler: Handles MCP resource fetching and attachment conversion
  • MCPPromptHandler: Manages MCP prompts for system instruction enhancement

Configuration Support

  • Added mcpServerConfigurations section to config.json for defining MCP servers
  • Extended connectors to accept mcpServers array alongside regular tools
  • Added comprehensive validation for all MCP configurations

Key Features

✅ MCP tools are automatically discovered and integrated with AI models
✅ MCP resources are converted to Discord attachments
✅ Support for both stdio (local) and SSE (remote) MCP servers
✅ Works seamlessly with existing tool infrastructure
✅ Comprehensive error handling and logging
✅ TypeScript types and full build compatibility

Example Configuration

{
  "mcpServerConfigurations": {
    "filesystem": {
      "transportType": "stdio",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/directory"]
    },
    "github": {
      "transportType": "stdio",
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "your-token"
      }
    }
  },
  "connectorConfigurations": {
    "ToolsOpenAIConnector": {
      "connectionOptions": {
        "tools": ["SearxingTool"],
        "mcpServers": ["filesystem", "github"]
      }
    }
  }
}

Documentation

  • Added comprehensive MCP_INTEGRATION.md guide with detailed setup instructions
  • Updated README.md with MCP features
  • Updated template.config.json with example MCP server configurations

How it works

  1. MCP servers are defined centrally in mcpServerConfigurations
  2. Connectors specify which MCP servers they want to use via mcpServers array
  3. On startup, the bot connects to all configured MCP servers
  4. MCP tools are automatically discovered and made available to AI models
  5. The tools work exactly like native tools - no special handling required

This implementation opens up exciting possibilities like filesystem access, GitHub integration, database queries, and much more through the growing MCP ecosystem.

Closes #3

- Implement MCPClient for stdio and SSE transport connections
- Add MCPManager for centralized MCP server management
- Create MCPToolAdapter to integrate MCP tools with existing infrastructure
- Add MCPResourceHandler and MCPPromptHandler for extended capabilities
- Update ConfigLoader to support mcpServerConfigurations
- Extend connectors to accept mcpServers array alongside tools
- Add comprehensive validation for MCP configurations
- Include MCP_INTEGRATION.md documentation
- Update README.md with MCP features
- Add example MCP configurations to template.config.json

Closes ZeldaFan0225#3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for MCP Servers

1 participant