examples.mcp_chat¶
Interactive chat with MCP tools.
View the complete module source at #L1-L187.
API details¶
Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.
examples.mcp_chat
¶
Interactive chat with MCP tools.
The LLM can use MCP tools (filesystem, etc.) to perform actions.
Usage
python examples/mcp_chat.py
Example prompts
- "Create a file at /tmp/test.txt with content hello world"
- "List files in /tmp"
- "Read the file /tmp/test.txt"
examples.mcp_chat.get_mcp_tools
¶
Get MCP tools in OpenAI format.
Source code in examples/mcp_chat.py
examples.mcp_chat.execute_tool
¶
examples.mcp_chat.chat
¶
Send message to LLM with tools.
Source code in examples/mcp_chat.py
examples.mcp_chat.main
¶
Source code in examples/mcp_chat.py
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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
Complete contract reference¶
Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.
examples.mcp_chat.get_mcp_tools · function
Get MCP tools in OpenAI format.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated - Direct return expressions:
tools
Exceptions and behavior
Function get_mcp_tools calls requests.get(f'{BASE_URL}/v1/mcp/tools').json, requests.get, response.get, tools.append; returns tools.
No direct raise statement appears in this definition.
examples.mcp_chat.execute_tool · function
Execute an MCP tool.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tool_name |
str |
yes |
none |
Required positional or keyword input. |
arguments |
dict |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
response
Exceptions and behavior
Function execute_tool calls requests.post(f'{BASE_URL}/v1/mcp/execute', json={'tool_name': tool_name, 'arguments': arguments}).json, requests.post; returns response.
No direct raise statement appears in this definition.
examples.mcp_chat.chat · function
Send message to LLM with tools.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
messages |
list |
yes |
none |
Required positional or keyword input. |
tools |
list |
yes |
none |
Required positional or keyword input. |
Returns
- Type:
not annotated - Direct return expressions:
{'error': f'HTTP {response.status_code}: {response.text[:200]}'};response.json();{'error': 'Request timed out'};{'error': f'Invalid JSON response: {e}'}
Exceptions and behavior
Function chat calls requests.post, response.json; has 4 explicit return paths.
No direct raise statement appears in this definition.
examples.mcp_chat.main · function
Function main calls print, get_mcp_tools, len, '\n'.join; returns None.
Parameters
This callable has no explicit inputs.
Returns
- Type:
not annotated - Direct return expressions:
None
Exceptions and behavior
Function main calls print, get_mcp_tools, len, '\n'.join; returns None.
No direct raise statement appears in this definition.
Complete symbol map¶
This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.
| Symbol | Kind | Signature and inputs | What it does | Source |
|---|---|---|---|---|
get_mcp_tools |
function | get_mcp_tools() -> not annotated |
Get MCP tools in OpenAI format. | #L22-L35 |
execute_tool |
function | execute_tool(tool_name: str, arguments: dict) -> not annotated |
Execute an MCP tool. | #L38-L44 |
chat |
function | chat(messages: list, tools: list) -> not annotated |
Send message to LLM with tools. | #L47-L66 |
main |
function | main() -> not annotated |
Function main calls print, get_mcp_tools, len, '\n'.join; returns None. |
#L69-L183 |