1"use strict";(self.webpackChunkintellidocs=self.webpackChunkintellidocs||[]).push([[5477],{6899:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>a,contentTitle:()=>l,default:()=>h,frontMatter:()=>s,metadata:()=>i,toc:()=>c});var o=n(4848),r=n(8453);const s={sidebar_position:3,title:"MCP Client for Python Flows",sidebar_label:"MCP Client",description:"Learn how to call MCP tools from Intelli Python flows using local servers, HTTP endpoints, headers, SSE transport, timeouts, and tool parameters.",keywords:["python mcp client","intelli mcp agent","mcp tools python flow","mcp http client","mcp sse transport","intelli flow mcp"]},l="MCP Client",i={id:"python/mcp/client",title:"MCP Client for Python Flows",description:"Learn how to call MCP tools from Intelli Python flows using local servers, HTTP endpoints, headers, SSE transport, timeouts, and tool parameters.",source:"@site/docs/python/mcp/client.md",sourceDirName:"python/mcp",slug:"/python/mcp/client",permalink:"/docs/python/mcp/client",draft:!1,unlisted:!1,editUrl:"https://github.com/intelligentnode/docs/edit/main/intellidocs/docs/python/mcp/client.md",tags:[],version:"current",sidebarPosition:3,frontMatter:{sidebar_position:3,title:"MCP Client for Python Flows",sidebar_label:"MCP Client",description:"Learn how to call MCP tools from Intelli Python flows using local servers, HTTP endpoints, headers, SSE transport, timeouts, and tool parameters.",keywords:["python mcp client","intelli mcp agent","mcp tools python flow","mcp http client","mcp sse transport","intelli flow mcp"]},sidebar:"pythonSidebar",previous:{title:"MCP Server",permalink:"/docs/python/mcp/server"},next:{title:"Introduction",permalink:"/docs/python/controllers/introduction"}},a={},c=[{value:"How It Works",id:"how-it-works",level:2},{value:"Creating a Basic Client",id:"creating-a-basic-client",level:2},{value:"Connecting to a Remote HTTP Server",id:"connecting-to-a-remote-http-server",level:2},{value:"Connecting to a Third Party Server",id:"connecting-to-a-third-party-server",level:2},{value:"Generate flow visualization",id:"generate-flow-visualization",level:2},{value:"Building More Complex Flows",id:"building-more-complex-flows",level:2}];function p(e){const t={a:"a",code:"code",h1:"h1",h2:"h2",li:"li",ol:"ol",p:"p",pre:"pre",...(0,r.R)(),...e.components};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(t.h1,{id:"mcp-client",children:"MCP Client"}),"\n",(0,o.jsx)(t.p,{children:"Once you've created an MCP server with your custom tools, you need a way to call those tools from your Intelli flow. This is where the MCP client comes in."}),"\n",(0,o.jsx)(t.h2,{id:"how-it-works",children:"How It Works"}),"\n",(0,o.jsx)(t.p,{children:"The process follows these steps:"}),"\n",(0,o.jsxs)(t.ol,{children:["\n",(0,o.jsx)(t.li,{children:"Your flow creates an MCP agent that knows how to talk to your server."}),"\n",(0,o.jsx)(t.li,{children:"The agent calls a specific tool with parameters."}),"\n",(0,o.jsx)(t.li,{children:"The server processes the request and returns a result."}),"\n",(0,o.jsx)(t.li,{children:"Your flow continues with that result."}),"\n"]}),"\n",(0,o.jsx)(t.h2,{id:"creating-a-basic-client",children:"Creating a Basic Client"}),"\n",(0,o.jsxs)(t.p,{children:["Create a file named ",(0,o.jsx)(t.code,{children:"simple_mcp_client.py"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-python",children:'# simple_mcp_client.py\nimport asyncio\nimport sys\nfrom intelli.flow.agents.agent import Agent\nfrom intelli.flow.tasks.task import Task\nfrom intelli.flow.input.task_input import TextTaskInput\nfrom intelli.flow.flow import Flow\nfrom intelli.flow.types import AgentTypes\n\n# Create an MCP agent that will call our math server\nmcp_agent = Agent(\n agent_type=AgentTypes.MCP.value,\n provider="mcp",\n mission="Do math operations",\n model_params={\n "command": sys.executable,\n "args": ["mcp_math_server.py"], # Path to your server file\n "tool": "add", # Which tool to call\n "arg_a": 7, # First parameter\n "arg_b": 8, # Second parameter\n }\n)\n\n# Create a task that uses this agent\ncalc_task = Task(\n TextTaskInput("Calculate"),\n mcp_agent,\n log=True\n)\n\n# Create a flow\nflow = Flow(\n tasks={"calc": Task(TextTaskInput("Calculate"), http_mcp_agent)}, \n map_paths={"calc": []}, # Empty list = No outgoing connections from this task\n log=True\n)\n\n# Ru
1n the flow and print the result\nif __name__ == "__main__":\n print("Running MCP math flow...")\n result = asyncio.run(flow.start())\n print(f"Result: 7 + 8 = {result[\'calc\'][\'output\']}")\n'})}),"\n",(0,o.jsx)(t.p,{children:"Run it with:"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-bash",children:"python simple_mcp_client.py\n"})}),"\n",(0,o.jsx)(t.h2,{id:"connecting-to-a-remote-http-server",children:"Connecting to a Remote HTTP Server"}),"\n",(0,o.jsx)(t.p,{children:"If your MCP server runs as an HTTP service (as shown in the Server page), connect to it like this:"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-python",children:'# http_client.py\nimport asyncio\nimport sys\nfrom intelli.flow.agents.agent import Agent\nfrom intelli.flow.tasks.task import Task\nfrom intelli.flow.input.task_input import TextTaskInput\nfrom intelli.flow.flow import Flow\nfrom intelli.flow.types import AgentTypes\n\n# Create an MCP agent that connects to an HTTP server\nhttp_mcp_agent = Agent(\n agent_type=AgentTypes.MCP.value,\n provider="mcp",\n mission="Do math remotely",\n model_params={\n "url": "http://localhost:8000/mcp", # URL to your HTTP server\n "tool": "add", # Which tool to call\n "arg_a": 15, # First parameter\n "arg_b": 27, # Second parameter\n }\n)\n\n# ... (rest is the same - create task, flow, etc.) ...\n'})}),"\n",(0,o.jsx)(t.h2,{id:"connecting-to-a-third-party-server",children:"Connecting to a Third Party Server"}),"\n",(0,o.jsxs)(t.p,{children:["Most hosted MCP servers need an API key, and some of them expose the SSE transport instead of the streamable HTTP one. Pass those options in the same ",(0,o.jsx)(t.code,{children:"model_params"}),":"]}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-python",children:'remote_agent = Agent(\n agent_type=AgentTypes.MCP.value,\n provider="mcp",\n mission="Call a hosted tool",\n model_params={\n "url": "https://tools.example.com/mcp",\n "headers": {"Authorization": f"Bearer {API_TOKEN}"},\n "transport": "sse", # use it when the server exposes /sse\n "timeout": 30, # seconds allowed per call\n "tool": "search",\n "arg_query": "intelli framework",\n }\n)\n'})}),"\n",(0,o.jsx)(t.p,{children:"The same options are available on the wrapper when you call tools directly:"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-python",children:'from intelli.wrappers.mcp_wrapper import MCPWrapper\nfrom intelli.wrappers.mcp_config import http_server_config, sse_server_config\n\nwrapper = MCPWrapper(http_server_config(\n "https://tools.example.com/mcp",\n headers={"Authorization": f"Bearer {API_TOKEN}"},\n timeout=30,\n))\n\nwith wrapper.connect():\n tools = wrapper.discover_tools()\n result = wrapper.execute_tool("search", {"query": "intelli framework"})\n'})}),"\n",(0,o.jsxs)(t.p,{children:["Use ",(0,o.jsx)(t.code,{children:"sse_server_config"})," with the same arguments for the SSE transport, and ",(0,o.jsx)(t.code,{children:"websocket_server_config"})," for a WebSocket server."]}),"\n",(0,o.jsx)(t.h2,{id:"generate-flow-visualization",children:"Generate flow visualization"}),"\n",(0,o.jsx)(t.pre,{children:(0,o.jsx)(t.code,{className:"language-python",children:'graph_path = flow.generate_graph_img(\n name="math_flow_graph", # Base name for the output file\n save_path="./temp/graphs", # Directory to save the image\n)\n'})}),"\n",(0,o.jsx)(t.h2,{id:"building-more-complex-flows",children:"Building More Complex Flows"}),"\n",(0,o.jsx)(t.p,{children:"In real applications, you'll often:"}),"\n",(0,o.jsxs)(t.ol,{children:["\n",(0,o.jsx)(t.li,{children:"Use an LLM to interpret user requests."}),"\n",(0,o.jsx)(t.li,{children:"Extract operation and parameters."}),"\n",(0,o.jsx)(t.li,{children:"Call the appropriate MCP tool."}),"\n",(0,o.jsx)(t.li,{children:"Present results back to the user."}),"\n"]}),"\n",(0,o.jsxs)(t.p,{children:["A complete example that does this:\n\ud83d\udd17 ",(0,o.jsx)(t.a,{href:"https://github.com/intelligentnode/Intelli/blob/main/sample/http_mcp/http_mcp_calculator_server.py",children:(0,o.jsx)(t.code,{children:"Http(s) Server"})}),"\n\ud83d\udd17 ",(0,o.jsx)(t.a,{href:"https://github.com/intelligentnode/Intelli/blob/main/sample/http_mcp/http_math_flow_client.py",children:(0,o.jsx)(t.code,{children:"Http(s) Client"})})]})]})}function h(e={}){const{wrapper:t}={...(0,r.R)(),...e.components};return t?(0,o.jsx)(t,{...e,children:(0,o.jsx)(p,{...e})}):p(e)}},8453:(e,t,n)=>{n.d(t,{R:()=>l,x:()=>i});var o=n(6540);const r={},s=o.createContext(r);function l(e){const t=o.useContext(s);return o.useMemo((function(){return"function"==typeof e?e(t):{...t,...e}}),[t,e])}function i(e){let t;return t=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:l(e.components),o.createElement(s.Provider,{value:t},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.