Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Conversation

@jinglemansweep
Copy link
Contributor

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

  • Added a new mcp CLI command to meshcore_api, enabling users to start the MCP server with configurable options for host, port, API URL, authentication, logging, and stdio mode.
  • Implemented the MCP server in the new 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]
  • Added the mcp Python package dependency to support the FastMCP protocol and tool registration.

Documentation and Usage

  • Updated README.md and AGENTS.md to 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

  • Added MCP server service to docker-compose.yml, enabling easy deployment alongside the MeshCore API server with environment-based configuration. [1] [2]
  • Added a VSCode MCP configuration example for seamless integration with Claude and other LLMs.

These changes collectively enable AI-powered tools to interact with the MeshCore mesh network in a secure, scalable, and decoupled manner.

Copilot AI review requested due to automatic review settings December 1, 2025 23:57
@jinglemansweep jinglemansweep merged commit 947dd03 into main Dec 1, 2025
5 checks passed
@jinglemansweep jinglemansweep deleted the feature/mcp branch December 1, 2025 23:58
Copy link

Copilot AI left a 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

Comment on lines +9 to +11
# API configuration
api_url: Optional[str] = None
api_token: Optional[str] = None
Copy link

Copilot AI Dec 2, 2025

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...
Suggested change
# 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

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +3
"""MeshCore MCP Server - Model Context Protocol integration."""

__version__ = "0.1.0"
Copy link

Copilot AI Dec 2, 2025

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 variables
  • test_mcp_state.py: Test state management and API configuration
  • test_mcp_client.py: Test HTTP client functionality and error handling
  • test_mcp_tools.py: Test tool registration and execution
  • test_mcp_server.py: Test server creation and startup

Copilot uses AI. Check for mistakes.
Comment on lines +97 to +106
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')
Copy link

Copilot AI Dec 2, 2025

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)}"

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +28
@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)
Copy link

Copilot AI Dec 2, 2025

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)}"

Copilot uses AI. Check for mistakes.
Comment on lines +111 to +115
if len(destination) != 64:
return (
f"Error: destination must be a 64-character public key "
f"(got {len(destination)} characters)"
)
Copy link

Copilot AI Dec 2, 2025

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"

Copilot uses AI. Check for mistakes.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants