feat: create MCP server using FastMCP and set up integration test

pull/819/head
Pavan Kumar 3 days ago committed by ascender1729
parent 9859fcfd2a
commit d7c861604b

@ -4,7 +4,7 @@ modules = ["python-3.10", "bash"]
channel = "stable-24_05" channel = "stable-24_05"
[workflows] [workflows]
runButton = "Run Interactive Agents" runButton = "Test MCP Integration"
[[workflows.workflow]] [[workflows.workflow]]
name = "Run MCP Tests" name = "Run MCP Tests"
@ -23,3 +23,21 @@ mode = "sequential"
[[workflows.workflow.tasks]] [[workflows.workflow.tasks]]
task = "shell.exec" task = "shell.exec"
args = "python -m pytest tests/tools/test_mcp_integration.py::test_interactive_multi_agent_mcp -s" args = "python -m pytest tests/tools/test_mcp_integration.py::test_interactive_multi_agent_mcp -s"
[[workflows.workflow]]
name = "Run MCP Server"
author = 13983571
mode = "sequential"
[[workflows.workflow.tasks]]
task = "shell.exec"
args = "python examples/mcp_example/math_server.py"
[[workflows.workflow]]
name = "Test MCP Integration"
author = 13983571
mode = "sequential"
[[workflows.workflow.tasks]]
task = "shell.exec"
args = "python examples/mcp_example/test_integration.py"

@ -0,0 +1,17 @@
from fastmcp import FastMCP
mcp = FastMCP("Math-Server")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
@mcp.tool()
def multiply(a: int, b: int) -> int:
"""Multiply two numbers"""
return a * b
if __name__ == "__main__":
mcp.run(host="0.0.0.0", port=6274, transport="sse")

@ -0,0 +1,28 @@
from swarms import Agent
from swarms.prompts.finance_agent_sys_prompt import FINANCIAL_AGENT_SYS_PROMPT
from swarms.tools.mcp_integration import MCPServerSseParams
# Configure MCP server connection
server = MCPServerSseParams(
url="http://0.0.0.0:6274",
headers={"Content-Type": "application/json"}
)
# Initialize agent with MCP capabilities
agent = Agent(
agent_name="Math-Agent",
agent_description="Agent that performs math operations",
system_prompt=FINANCIAL_AGENT_SYS_PROMPT,
max_loops=1,
mcp_servers=[server],
streaming_on=True
)
# Test addition
result = agent.run("Use the add tool to add 5 and 3")
print("Addition result:", result)
# Test multiplication
result = agent.run("Use the multiply tool to multiply 4 and 6")
print("Multiplication result:", result)

@ -78,6 +78,7 @@ litellm = "*"
torch = "*" torch = "*"
httpx = "*" httpx = "*"
langchain-openai = "^0.3.14" langchain-openai = "^0.3.14"
fastmcp = "^2.2.0"
[tool.poetry.scripts] [tool.poetry.scripts]
swarms = "swarms.cli.main:main" swarms = "swarms.cli.main:main"

Loading…
Cancel
Save