-
Notifications
You must be signed in to change notification settings - Fork 0
MCP Server #17
MCP Server #17
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a comprehensive MCP (Model Context Protocol) server implementation that enables AI/LLM integration with the MeshCore mesh network. The MCP server is architected as a standalone HTTP client that communicates exclusively with the MeshCore REST API, allowing it to run independently on separate infrastructure.
Key Changes:
- Added a complete MCP server implementation with HTTP and stdio transport modes
- Integrated MCP server command into the CLI with comprehensive configuration options
- Updated deployment configuration to support MCP server as a separate Docker service
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
tests/unit/test_config.py |
Updated test to reflect API port change from 8000 to 8080 |
test_webhooks.py |
Removed standalone webhook test server file |
src/meshcore_api/mcp/__init__.py |
Added MCP package initialization |
src/meshcore_api/mcp/config.py |
Implemented MCP server configuration with CLI/env variable support |
src/meshcore_api/mcp/state.py |
Added global state management for API connectivity |
src/meshcore_api/mcp/client.py |
Implemented HTTP client for MeshCore API requests |
src/meshcore_api/mcp/server.py |
Created MCP server entrypoints for HTTP and stdio modes |
src/meshcore_api/mcp/tools/__init__.py |
Added tools package initialization |
src/meshcore_api/mcp/tools/messages.py |
Implemented message query and send tools |
src/meshcore_api/mcp/tools/advertisements.py |
Implemented advertisement query and send tools |
src/meshcore_api/cli.py |
Added mcp command with comprehensive CLI options |
pyproject.toml |
Added mcp>=1.9.0 dependency |
docker-compose.yml |
Added MCP server service configuration |
README.md |
Added comprehensive MCP server documentation |
AGENTS.md |
Added MCP command usage documentation |
PLAN.md |
Removed project planning document |
.vscode/mcp.json |
Added VSCode MCP configuration example |
Comments suppressed due to low confidence (2)
src/meshcore_api/cli.py:7
- Import of 'Path' is not used.
from pathlib import Path
tests/unit/test_config.py:3
- Import of 'pytest' is not used.
import pytest
| # API configuration | ||
| api_url: Optional[str] = None | ||
| api_token: Optional[str] = None |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ServerState class uses class-level attributes for mutable state (api_url and api_token), which could lead to issues if multiple instances are created or in concurrent scenarios. Since a global singleton instance is created at line 37, consider using instance attributes initialized in __init__ instead.
Example:
class ServerState:
"""Maintains global server state for API connectivity."""
def __init__(self):
self.api_url: Optional[str] = None
self.api_token: Optional[str] = None
# rest of the methods...| # API configuration | |
| api_url: Optional[str] = None | |
| api_token: Optional[str] = None | |
| def __init__(self): | |
| self.api_url: Optional[str] = None | |
| self.api_token: Optional[str] = None |
| """MeshCore MCP Server - Model Context Protocol integration.""" | ||
|
|
||
| __version__ = "0.1.0" |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MCP server implementation lacks test coverage. Given that this repository has comprehensive unit testing for other components (as seen in the tests/unit/ directory), consider adding tests for the MCP server to maintain consistency with the project's testing standards.
Suggested test coverage:
test_mcp_config.py: Test configuration loading from CLI args and environment variablestest_mcp_state.py: Test state management and API configurationtest_mcp_client.py: Test HTTP client functionality and error handlingtest_mcp_tools.py: Test tool registration and executiontest_mcp_server.py: Test server creation and startup
| async def meshcore_send_direct_message( | ||
| destination: str, text: str, text_type: str = "plain" | ||
| ) -> str: | ||
| """ | ||
| Send a direct message to a specific node. | ||
|
|
||
| Args: | ||
| destination: Destination node public key (full 64 hex characters) | ||
| text: Message text content (1-1000 characters) | ||
| text_type: Text type - 'plain', 'cli_data', or 'signed_plain' (default: 'plain') |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider adding input validation for text_type to ensure it's one of the valid values ('plain', 'cli_data', 'signed_plain'). Currently, invalid values would be passed through to the API without client-side validation.
Example:
valid_text_types = ['plain', 'cli_data', 'signed_plain']
if text_type not in valid_text_types:
return f"Error: text_type must be one of {', '.join(valid_text_types)}"| @mcp.tool() | ||
| async def meshcore_get_advertisements( | ||
| node_public_key: Optional[str] = None, | ||
| adv_type: Optional[str] = None, | ||
| start_date: Optional[str] = None, | ||
| end_date: Optional[str] = None, | ||
| limit: int = 100, | ||
| offset: int = 0, | ||
| ) -> str: | ||
| """ | ||
| Query advertisements from the mesh network. | ||
|
|
||
| Args: | ||
| node_public_key: Filter by node public key (full 64 hex characters) | ||
| adv_type: Filter by advertisement type (none/chat/repeater/room) |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The validation for advertisement type should check against valid values. Consider adding validation similar to message types to ensure only valid advertisement types are passed to the API.
Based on the documentation comment, valid values appear to be: 'none', 'chat', 'repeater', 'room'. Consider adding:
if adv_type is not None:
valid_adv_types = ['none', 'chat', 'repeater', 'room']
if adv_type not in valid_adv_types:
return f"Error: adv_type must be one of {', '.join(valid_adv_types)}"| if len(destination) != 64: | ||
| return ( | ||
| f"Error: destination must be a 64-character public key " | ||
| f"(got {len(destination)} characters)" | ||
| ) |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation for the destination parameter only checks the length (64 characters) but doesn't validate that it contains only hexadecimal characters. Consider using the existing validate_public_key utility function from meshcore_api.utils.address to ensure the destination is both the correct length and contains only valid hex characters.
Example:
from ..utils.address import validate_public_key
if not validate_public_key(destination):
return "Error: destination must be a valid 64-character hexadecimal public key"
This pull request introduces a major new feature: the MeshCore MCP (Model Context Protocol) server for AI/LLM integration, allowing external AI assistants to interact with the MeshCore mesh network via a standardized HTTP interface. The MCP server is implemented as a standalone service that communicates exclusively with the MeshCore REST API, and can be run either as an HTTP server or in stdio mode. Documentation, configuration, and deployment scripts have been updated to support and describe this new capability.
MCP Server Implementation and Integration
mcpCLI command tomeshcore_api, enabling users to start the MCP server with configurable options for host, port, API URL, authentication, logging, and stdio mode.src/meshcore_api/mcp/package, including configuration management (config.py), HTTP client for API requests (client.py), server state management (state.py), tool registration (tools/), and server entrypoints (server.py). [1] [2] [3] [4] [5] [6]mcpPython package dependency to support the FastMCP protocol and tool registration.Documentation and Usage
README.mdandAGENTS.mdto document the MCP server, its architecture, usage examples, configuration options, available tools, and integration instructions for AI/LLM workflows. [1] [2] [3] [4]Deployment and Configuration
docker-compose.yml, enabling easy deployment alongside the MeshCore API server with environment-based configuration. [1] [2]These changes collectively enable AI-powered tools to interact with the MeshCore mesh network in a secure, scalable, and decoupled manner.