Skip to content

Commit cc23764

Browse files
committed
DOCS: fix MCP tool example scripts; add docs about HTTP transport
1 parent 65bbaa2 commit cc23764

4 files changed

Lines changed: 131 additions & 32 deletions

File tree

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,28 @@ mcp_tool = MCPTool(
188188
)
189189
```
190190

191+
Use an MCP server over HTTP from another machine:
192+
193+
```python
194+
from eaa.tool.mcp import MCPTool
195+
196+
mcp_tool = MCPTool(
197+
{
198+
"mcpServers": {
199+
"calculator": {
200+
"url": "http://SERVER_IP:8050/mcp",
201+
"transport": "http",
202+
}
203+
}
204+
}
205+
)
206+
```
207+
208+
For this remote HTTP setup, the server side must be started with
209+
``run_mcp_server_from_tools(..., transport="http", host="0.0.0.0", port=8050, path="/mcp")``.
210+
The client config must keep the server definition under ``mcpServers``; passing
211+
only ``{"url": ..., "transport": "http"}`` is not enough.
212+
191213
## Skills
192214

193215
Skills are reusable, markdown-first task packages that EAA can discover and

docs/tools.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,45 @@ interface.
9393
9494
task_manager.register_tools(mcp_tool)
9595
96+
To connect to an MCP server over HTTP from a different machine, configure the
97+
client with a named entry under ``mcpServers`` and point it at the server's MCP
98+
endpoint:
99+
100+
.. code-block:: python
101+
102+
from eaa.tool.mcp import MCPTool
103+
104+
mcp_tool = MCPTool(
105+
{
106+
"mcpServers": {
107+
"calculator": {
108+
"url": "http://SERVER_IP:8050/mcp",
109+
"transport": "http",
110+
}
111+
}
112+
}
113+
)
114+
115+
The server side should be started with HTTP transport enabled, for example:
116+
117+
.. code-block:: python
118+
119+
from eaa.core.mcp.server import run_mcp_server_from_tools
120+
from eaa.tool.example_calculator import CalculatorTool
121+
122+
run_mcp_server_from_tools(
123+
tools=CalculatorTool(),
124+
server_name="Calculator MCP Server",
125+
transport="http",
126+
host="0.0.0.0",
127+
port=8050,
128+
path="/mcp",
129+
)
130+
131+
Do not pass only ``{"url": ..., "transport": "http"}`` to ``MCPTool``. The
132+
FastMCP client expects a full config object with one or more named servers
133+
inside ``mcpServers``.
134+
96135
Notes:
97136

98137
- EAA normalizes tool results to JSON for tools served through the EAA MCP

examples/mcp_calculator_server.py

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
divide, get_history, clear_history) as MCP tools.
1313
"""
1414

15-
import sys
1615
import logging
16+
import inspect
17+
import sys
1718
from pathlib import Path
1819

1920
# Add the src directory to the Python path
2021
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
2122

22-
from eaa.mcp import run_mcp_server_from_tools
23+
from eaa.core.mcp.server import run_mcp_server_from_tools
2324
from eaa.tool.example_calculator import CalculatorTool
2425

2526
# Configure logging
@@ -31,18 +32,56 @@
3132
logger = logging.getLogger(__name__)
3233

3334

34-
def main():
35+
def log_available_tools(calculator: CalculatorTool) -> None:
36+
"""Log the exposed calculator tool methods."""
37+
logger.info("Created calculator tool with the following methods:")
38+
for spec in calculator.exposed_tools:
39+
doc = inspect.getdoc(spec.function) or "No description"
40+
logger.info(" - %s: %s", spec.name, doc.split(".")[0])
41+
42+
43+
def print_banner() -> None:
44+
"""Print usage information without corrupting stdio MCP transport."""
45+
print(
46+
"""
47+
Calculator MCP Server Example
48+
============================
49+
50+
This server exposes calculator operations as MCP tools:
51+
- add(a, b): Add two numbers
52+
- subtract(a, b): Subtract two numbers
53+
- multiply(a, b): Multiply two numbers
54+
- divide(a, b): Divide two numbers
55+
- get_history(): Get calculation history
56+
- clear_history(): Clear calculation history
57+
58+
Connect this server to your MCP client (like Cursor) to use these tools
59+
in AI conversations.
60+
61+
Press Ctrl+C to stop the server.
62+
""",
63+
file=sys.stderr,
64+
)
65+
66+
67+
def main() -> None:
3568
"""Main function to run the MCP calculator server."""
3669
try:
3770
# Create the calculator tool
3871
calculator = CalculatorTool()
39-
40-
logger.info("Created calculator tool with the following methods:")
41-
for tool_dict in calculator.exposed_tools:
42-
logger.info(f" - {tool_dict['name']}: {tool_dict['function'].__doc__.split('.')[0] if tool_dict['function'].__doc__ else 'No description'}")
43-
72+
log_available_tools(calculator)
73+
4474
# Create and run the MCP server
4575
logger.info("Starting MCP server...")
76+
# To expose this server over HTTP for remote clients instead of stdio, use:
77+
# run_mcp_server_from_tools(
78+
# tools=calculator,
79+
# server_name="Calculator MCP Server",
80+
# transport="http",
81+
# host="0.0.0.0",
82+
# port=8000,
83+
# path="/mcp",
84+
# )
4685
run_mcp_server_from_tools(
4786
tools=calculator,
4887
server_name="Calculator MCP Server",
@@ -56,22 +95,5 @@ def main():
5695

5796

5897
if __name__ == "__main__":
59-
print("""
60-
Calculator MCP Server Example
61-
============================
62-
63-
This server exposes calculator operations as MCP tools:
64-
- add(a, b): Add two numbers
65-
- subtract(a, b): Subtract two numbers
66-
- multiply(a, b): Multiply two numbers
67-
- divide(a, b): Divide two numbers
68-
- get_history(): Get calculation history
69-
- clear_history(): Clear calculation history
70-
71-
Connect this server to your MCP client (like Cursor) to use these tools
72-
in AI conversations.
73-
74-
Press Ctrl+C to stop the server.
75-
""")
76-
77-
main()
98+
print_banner()
99+
main()

src/eaa/tool/example_calculator.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
This module provides a simple calculator tool that can be exposed via MCP.
55
"""
66

7-
from typing import List
87
import logging
8+
from typing import Annotated, List
99

1010
from eaa.core.tooling.base import BaseTool, check, tool
1111

@@ -35,7 +35,11 @@ def __init__(
3535
self.calculation_history: List[str] = []
3636

3737
@tool(name="add")
38-
def add(self, a: float, b: float) -> float:
38+
def add(
39+
self,
40+
a: Annotated[float, "The first addend."],
41+
b: Annotated[float, "The second addend."],
42+
) -> float:
3943
"""
4044
Add two numbers together.
4145
@@ -57,7 +61,11 @@ def add(self, a: float, b: float) -> float:
5761
return result
5862

5963
@tool(name="subtract")
60-
def subtract(self, a: float, b: float) -> float:
64+
def subtract(
65+
self,
66+
a: Annotated[float, "The number to subtract from."],
67+
b: Annotated[float, "The number to subtract."],
68+
) -> float:
6169
"""
6270
Subtract the second number from the first.
6371
@@ -79,7 +87,11 @@ def subtract(self, a: float, b: float) -> float:
7987
return result
8088

8189
@tool(name="multiply")
82-
def multiply(self, a: float, b: float) -> float:
90+
def multiply(
91+
self,
92+
a: Annotated[float, "The first factor."],
93+
b: Annotated[float, "The second factor."],
94+
) -> float:
8395
"""
8496
Multiply two numbers together.
8597
@@ -101,7 +113,11 @@ def multiply(self, a: float, b: float) -> float:
101113
return result
102114

103115
@tool(name="divide")
104-
def divide(self, a: float, b: float) -> float:
116+
def divide(
117+
self,
118+
a: Annotated[float, "The dividend."],
119+
b: Annotated[float, "The non-zero divisor."],
120+
) -> float:
105121
"""
106122
Divide the first number by the second.
107123

0 commit comments

Comments
 (0)