-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmcp2_streamable_http.py
More file actions
executable file
·114 lines (80 loc) · 2.08 KB
/
mcp2_streamable_http.py
File metadata and controls
executable file
·114 lines (80 loc) · 2.08 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python3
# Copyright (c) 2025-2026 Datalayer, Inc.
# Distributed under the terms of the Modified BSD License.
"""
MCP Server 2 - Echo & String Tools
Simple MCP server providing string manipulation operations.
"""
from mcp.server.fastmcp import FastMCP
# Create MCP server
mcp = FastMCP("echo-server")
@mcp.tool()
def ping() -> str:
"""Simple ping that returns 'pong'.
Returns:
The string 'pong'
"""
return "pong"
@mcp.tool()
def echo(message: str) -> str:
"""Echo back the provided message.
Args:
message: Message to echo back
Returns:
The same message
"""
return message
@mcp.tool()
def reverse(text: str) -> str:
"""Reverse a string.
Args:
text: Text to reverse
Returns:
Reversed text
"""
return text[::-1]
@mcp.tool()
def uppercase(text: str) -> str:
"""Convert text to uppercase.
Args:
text: Text to convert
Returns:
Uppercased text
"""
return text.upper()
@mcp.tool()
def lowercase(text: str) -> str:
"""Convert text to lowercase.
Args:
text: Text to convert
Returns:
Lowercased text
"""
return text.lower()
@mcp.tool()
def count_words(text: str) -> int:
"""Count the number of words in text.
Args:
text: Text to analyze
Returns:
Number of words
"""
return len(text.split())
0
@mcp.tool()
def concatenate(strings: list[str], separator: str = " ") -> str:
"""Concatenate an array of strings with a separator.
Args:
strings: Array of strings to concatenate
separator: Separator to use between strings (default: space)
Returns:
Concatenated string
"""
return separator.join(strings)
if __name__ == "__main__":
# Run as Streamable HTTP server
import uvicorn
# Create the FastAPI app with streamable HTTP transport
app = mcp.streamable_http_app()
# Run with uvicorn on port 8082
uvicorn.run(app, host="0.0.0.0", port=8082)