Skip to content

Conversation

@moarshy
Copy link
Contributor

@moarshy moarshy commented Mar 12, 2025

This PR adds a MCP server implementation for Naptha.

Whats been done

  • Implemented a dedicated MCP server that uses the MCP SDK (node/mcp)
  • launch and stop script modified with launching script for MCP
  • Dockerfile for standalone MCP
  • docker-compose file modified to start mcp

To test

  • clone this branch
  • copy .env.sample to .env (set it up)
  • execute ./launch.sh
  • test with the below script
import asyncio
from mcp import ClientSession
from mcp.client.sse import sse_client
import json


async def test_mcp_connection():
    print("Connecting to MCP server via SSE...")
    
    # Connect to the SSE endpoint - this is the proper way to connect
    # Do NOT use the /messages/ endpoint directly with HTTP POST
    async with sse_client(url="http://100.26.170.209:8000/sse") as streams:
        async with ClientSession(*streams) as session:
            try:
                # Initialize the session
                print("Initializing session...")
                await session.initialize()
                
                # List available tools
                print("Listing tools...")
                response = await session.list_tools()
                tools = [tool.name for tool in response.tools]
                print(f"Available tools: {tools}")
                
                # Test the echo tool
                print("\nTesting echo tool...")
                echo_result = await session.call_tool("echo", {"message": "Hello from MCP!"})
                
                # Print the result
                for item in echo_result.content:
                    if item.type == "text":
                        print(f"Echo response: {item.text}")
                
                # Test the hello tool
                print("\nTesting hello tool...")
                hello_result = await session.call_tool("hello", {"name": "Claude"})
                
                # Print the result
                for item in hello_result.content:
                    if item.type == "text":
                        print(f"Hello response: {item.text}")
                
                # Test the fetch tool
                print("\nTesting fetch tool...")
                fetch_result = await session.call_tool("fetch", {"url": "https://example.com"})
                
                # Print the result
                for item in fetch_result.content:
                    if item.type == "text":
                        # Print first 500 characters
                        content_preview = item.text[:500] + "..." if len(item.text) > 500 else item.text
                        print(f"\nFetched content (preview):\n{content_preview}")
                    else:
                        print(f"Received content of type: {item.type}")
                
            except Exception as e:
                print(f"Error during MCP communication: {e}")

await test_mcp_connection()

moarshy added 5 commits March 12, 2025 06:27
- Create Dockerfile-mpc for MPC server containerization
- Update docker-compose.development.yml to include MPC server service
- Enhance server.py with graceful shutdown and health check endpoint
- Configure development mode with live reloading and source code mounting
.env.example Outdated
ROUTING_URL=ws://node.naptha.ai:8765

# Naptha MPC Server
MPC_SERVER_PORT=8000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mcp not mpc. we will need to change all of these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course. thanks for spotting the blunder

@moarshy moarshy changed the title Add MPC server on both (systemd/launchd and docker) Add MCP server on both (systemd/launchd and docker) Mar 12, 2025
- Add NapthaMCPClient for interacting with MCP servers
- Introduce new tools including echo_tool for message handling
- Update server.py to support multiple SSE endpoints
- Modify pyproject.toml to include naptha-sdk as a dependency
- Create .python-version file to specify Python version 3.12
moarshy added 2 commits March 15, 2025 14:32
…ection support

- Introduce /sse3 endpoint for handling requests with a generic MCP server script
- Update server initialization to accept a script path for dynamic tool execution
- Improve error handling and logging for MCP client connections
- Refactor client to support direct execution of MCP server scripts via stdio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants