diff --git a/.replit b/.replit index 94c2d07b..9aa01fa8 100644 --- a/.replit +++ b/.replit @@ -4,7 +4,7 @@ modules = ["python-3.10", "bash"] channel = "stable-24_05" [workflows] -runButton = "Run Interactive Agents" +runButton = "Test MCP Integration" [[workflows.workflow]] name = "Run MCP Tests" @@ -23,3 +23,21 @@ mode = "sequential" [[workflows.workflow.tasks]] task = "shell.exec" 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" diff --git a/examples/mcp_example/math_server.py b/examples/mcp_example/math_server.py new file mode 100644 index 00000000..2be29417 --- /dev/null +++ b/examples/mcp_example/math_server.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") diff --git a/examples/mcp_example/test_integration.py b/examples/mcp_example/test_integration.py new file mode 100644 index 00000000..1d583158 --- /dev/null +++ b/examples/mcp_example/test_integration.py @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 8142ceb6..5d9da9e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,6 +78,7 @@ litellm = "*" torch = "*" httpx = "*" langchain-openai = "^0.3.14" +fastmcp = "^2.2.0" [tool.poetry.scripts] swarms = "swarms.cli.main:main"