Model Context Protocol (MCP): Difference between revisions
Jump to navigation
Jump to search
Line 22: | Line 22: | ||
sudo chmod 4755 /usr/local/lib/node_modules/electron/dist/chrome-sandbox | sudo chmod 4755 /usr/local/lib/node_modules/electron/dist/chrome-sandbox | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Writing a Server (Python)= | |||
To demonstrate how easy this is [https://youtu.be/wa_A0qY0anA?si=8sWmPyiltuOBhJgB Matthew Berman]. There is just this code and a config | |||
<syntaxhighlight lang="py"> | |||
from mcp.server.fastmcp import FastMCP | |||
import time | |||
import signal | |||
import sys | |||
# Handle SIGINT (Ctrl+C) gracefully | |||
def signal_handler(sig, frame): | |||
print("Shutting down server gracefully...") | |||
sys.exit(0) | |||
signal.signal(signal.SIGINT, signal_handler) | |||
# Create an MCP server with increased timeout | |||
mcp = FastMCP( | |||
name="count-r", | |||
host="127.0.0.1", | |||
port=5000, | |||
# Add this to make the server more resilient | |||
timeout=30 # Increase timeout to 30 seconds | |||
) | |||
# Define our tool | |||
@mcp.tool() | |||
def count_r(word: str) -> int: | |||
"""Count the number of 'r' letters in a given word.""" | |||
try: | |||
# Add robust error handling | |||
if not isinstance(word, str): | |||
return 0 | |||
return word.lower().count("r") | |||
except Exception as e: | |||
# Return 0 on any error | |||
return 0 | |||
if __name__ == "__main__": | |||
try: | |||
print("Starting MCP server 'count-r' on 127.0.0.1:5000") | |||
# Use this approach to keep the server running | |||
mcp.run() | |||
except Exception as e: | |||
print(f"Error: {e}") | |||
# Sleep before exiting to give time for error logs | |||
time.sleep(5) | |||
</syntaxhighlight> | |||
Then change the config for claude. |
Revision as of 04:28, 17 March 2025
Introduction
This is my first foray into MCPs which works
Clients
- Claude
- Claude Code
- Cursor
- Windsurf
Servers
Example server site is awesome-mcp-servers
Installing Claude on Ubuntu 24.04
This was reasonably painless. Goto here. When installing the instructions are
git clone https://github.com/aaddrick/claude-desktop-debian.git
cd claude-desktop-debian
# Build the package
sudo ./build-deb.sh
sudo dpkg -i ./build/electron-app/claude-desktop_0.8.0_amd64.deb
This all goes well except the version of claude is now 0.8.1 and the script in the repository is 0.8.0. Search and replace the build-deb.sh and then it fails to launch because of sandbox issues which can be fixed, in my case, with
sudo chmod 4755 /usr/local/lib/node_modules/electron/dist/chrome-sandbox
Writing a Server (Python)
To demonstrate how easy this is Matthew Berman. There is just this code and a config
from mcp.server.fastmcp import FastMCP
import time
import signal
import sys
# Handle SIGINT (Ctrl+C) gracefully
def signal_handler(sig, frame):
print("Shutting down server gracefully...")
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
# Create an MCP server with increased timeout
mcp = FastMCP(
name="count-r",
host="127.0.0.1",
port=5000,
# Add this to make the server more resilient
timeout=30 # Increase timeout to 30 seconds
)
# Define our tool
@mcp.tool()
def count_r(word: str) -> int:
"""Count the number of 'r' letters in a given word."""
try:
# Add robust error handling
if not isinstance(word, str):
return 0
return word.lower().count("r")
except Exception as e:
# Return 0 on any error
return 0
if __name__ == "__main__":
try:
print("Starting MCP server 'count-r' on 127.0.0.1:5000")
# Use this approach to keep the server running
mcp.run()
except Exception as e:
print(f"Error: {e}")
# Sleep before exiting to give time for error logs
time.sleep(5)
Then change the config for claude.