Repository navigation
Expand file tree
/
Copy pathserver.py
More file actions
49 lines (41 loc) · 1.5 KB
/
Copy pathserver.py
File metadata and controls
49 lines (41 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
text-utils MCP Server
======================
A minimal FastMCP server exposing two text-processing tools:
word_count and char_count.
Trimmed down intentionally for a first real deployment -- fewer moving
parts to debug while learning the DigitalOcean / systemd / Caddy pipeline.
More tools can be added back later once the deployment itself is solid.
Run locally (STDIO transport, for use with Claude Desktop / Claude Code):
uv run server.py
Run over HTTP (for remote/droplet deployment):
uv run server.py --http
"""
import re
import sys
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("text-utils")
@mcp.tool()
def word_count(text: str) -> int:
"""Count the number of words in the given text (whitespace-separated)."""
return len(text.split())
@mcp.tool()
def char_count(text: str, include_spaces: bool = True) -> int:
"""
Count the number of characters in the given text.
Args:
text: The text to measure.
include_spaces: If False, whitespace characters are excluded from the count.
"""
if include_spaces:
return len(text)
return len(re.sub(r"\s", "", text))
if __name__ == "__main__":
if "--http" in sys.argv:
# Streamable HTTP transport, for droplet / remote deployment.
# Binds to 0.0.0.0:8000 by default so Caddy (running on the same
# box) can reverse-proxy to it over localhost.
mcp.run(transport="streamable-http")
else:
# STDIO transport, for local Claude Desktop / Claude Code use.
mcp.run()