# `examples.mcp_chat`

Interactive chat with MCP tools.

[View the complete module source at #L1-L187](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/mcp_chat.py#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
    options:
      members:
        - BASE_URL
        - get_mcp_tools
        - execute_tool
        - chat
        - main
      filters: []
      show_if_no_docstring: true

## 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.

<details class="api-contract" id="contract-examples.mcp_chat.get_mcp_tools" markdown="1">
<summary><code>examples.mcp_chat.get_mcp_tools</code> · function</summary>

```python
examples.mcp_chat.get_mcp_tools() -> not annotated
```

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.

[View source #L22-L35](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/mcp_chat.py#L22-L35).

</details>

<details class="api-contract" id="contract-examples.mcp_chat.execute_tool" markdown="1">
<summary><code>examples.mcp_chat.execute_tool</code> · function</summary>

```python
examples.mcp_chat.execute_tool(tool_name: str, arguments: dict) -> not annotated
```

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.

[View source #L38-L44](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/mcp_chat.py#L38-L44).

</details>

<details class="api-contract" id="contract-examples.mcp_chat.chat" markdown="1">
<summary><code>examples.mcp_chat.chat</code> · function</summary>

```python
examples.mcp_chat.chat(messages: list, tools: list) -> not annotated
```

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.

[View source #L47-L66](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/mcp_chat.py#L47-L66).

</details>

<details class="api-contract" id="contract-examples.mcp_chat.main" markdown="1">
<summary><code>examples.mcp_chat.main</code> · function</summary>

```python
examples.mcp_chat.main() -> not annotated
```

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.

[View source #L69-L183](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/mcp_chat.py#L69-L183).

</details>

## 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`](#contract-examples.mcp_chat.get_mcp_tools) | function | `get_mcp_tools() -> not annotated` | Get MCP tools in OpenAI format. | [#L22-L35](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/mcp_chat.py#L22-L35) |
| [`execute_tool`](#contract-examples.mcp_chat.execute_tool) | function | `execute_tool(tool_name: str, arguments: dict) -> not annotated` | Execute an MCP tool. | [#L38-L44](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/mcp_chat.py#L38-L44) |
| [`chat`](#contract-examples.mcp_chat.chat) | function | `chat(messages: list, tools: list) -> not annotated` | Send message to LLM with tools. | [#L47-L66](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/mcp_chat.py#L47-L66) |
| [`main`](#contract-examples.mcp_chat.main) | function | `main() -> not annotated` | Function `main` calls `print`, `get_mcp_tools`, `len`, `'\n'.join`; returns `None`. | [#L69-L183](https://github.com/waybarrios/vllm-mlx/blob/a69d47912bcb21d8fe04d48f75fa896b620ffcfa/examples/mcp_chat.py#L69-L183) |
