# MCP server (/features/ai/mcp-server)

Can your own AI coding assistant use VBT directly? The VBT MCP server connects any client that
supports the Model Context Protocol, such as Claude Code, Codex, or Cursor, to your installation, so
the assistant can search the documentation, look up the API, read source code, and run Python
backtests. Keep working in your editor while the assistant checks VBT examples and tests changes
against your installed package.

```bash title="Register the server with Claude Code"
vbt mcp config claude-code  # (1)
claude mcp add --transport stdio vectorbtpro -- /path/to/python -m vectorbtpro.mcp_server
```

1.  Prints the command for your client with the path to the Python interpreter that runs VBT filled
    in. `vbt mcp config` also supports `codex`, `cursor`, `vscode`, `gemini-cli`, `opencode`, and
    `claude-desktop`.

Asked to add a 5% stop loss and a 10% take profit to a moving average crossover, an assistant
connected to the server makes calls like these. The tools are Python functions in `vbt.mcp`, so the
same calls run without a server:

```python title="Search, resolve, and run, as an assistant does through the server"
>>> import json
>>> from vectorbtpro import mcp

>>> found = mcp.search(  # (1)
...     "stop loss and take profit in from_signals",
...     asset_names=["docs"],
...     n=3,
... )
>>> for result in json.loads(found):
...     print(result["name"])
Stop signals
Discretionary Signal Backtesting
High-level VBT

>>> print(mcp.resolve_refnames(["vbt.PF.from_signals"]))  # (2)
OK vbt.PF.from_signals vectorbtpro.portfolio.base.Portfolio.from_signals

>>> print(mcp.run_code("""
... data = vbt.YFData.pull("BTC-USD", start="2020-01-01", end="2025-01-01")
... fast = data.close.vbt.rolling_mean(20)
... slow = data.close.vbt.rolling_mean(50)
... pf = vbt.PF.from_signals(
...     data,
...     fast.vbt.crossed_above(slow),
...     fast.vbt.crossed_below(slow),
...     sl_stop=0.05,
...     tp_stop=0.10,
...     fees=0.001,
... )
... print(pf.stats(["total_return", "max_dd", "total_trades", "win_rate"]))
... """))  # (3)
Total Return [%]   -18.880116
Max Drawdown [%]    38.686652
Total Trades               19
Win Rate [%]        26.315789
dtype: object
```

1.  Searches only the documentation and returns the three best matches as JSON, which is what the
    assistant reads.
2.  Confirms the exact object before the assistant reads its API or source.
3.  Runs the code in a Jupyter kernel with VBT imported, and keeps the kernel's variables for later
    calls.

The assistant found the tutorial on stop signals, confirmed the method, and ran a real backtest in
your environment. You get the code and calculated statistics together, ready to inspect the trades,
adjust the settings, and run the next comparison.

## From a question to a tested backtest \[#from-a-question-to-a-tested-backtest]

The connection is useful throughout a research project. You can ask your assistant to:

*   Find the VBT method and examples for a strategy idea before writing the code.
*   Read the relevant API and source to investigate an error in your backtest.
*   Compare fees, slippage, or stop settings and show the resulting statistics.
*   Use [walk-forward validation](/features/optimization/time-series-cross-validation/) to test chosen
    parameters on later data.

For example, after the backtest above, ask it to compare the same strategy with and without stops
while keeping fees and signals fixed. The persistent kernel keeps `data`, `fast`, `slow`, and `pf`
available for follow-up calls, so the assistant can reuse the loaded data and inspect the trades.

You can also give it a member page URL and ask it to read the page. The server retrieves the text
from the release's [knowledge assets](/features/ai/knowledge-search/#knowledge-assets), using your
configured GitHub access. It does not need to control your browser or use its sign-in session. Long
pages can be read section by section, and community answers can be opened as whole threads.

## Agent skills for research tasks \[#agent-skills-for-research-tasks]

VBT ships with step-by-step instructions for common tasks, including backtesting, indicators,
parameter optimization, and cross-validation. The assistant can discover them through `list_skills`
and read the relevant instructions with `get_skill`. This gives it a procedure to follow alongside
the API reference and code examples.

For a parameter search, for example, the cross-validation skill covers train and test periods,
indicator warmup, and what happens to open positions when parameters change. The
[members-only skills pages](https://members.vectorbt.pro/using-ai/skills/) show the procedures available to your
assistant.

## Server \[#server]

The server runs on your machine with your VBT installation, so API and source lookups use the
version you have installed. Clients usually start it themselves over stdio. To run it in another
environment, such as a container or WSL, start it over HTTP with
`vbt mcp serve --transport streamable-http --port 8000` and register its `/mcp` address in the
client. Over HTTP, the server binds to the local machine by default. `run_code`, which executes
code, is available only over stdio.

Over stdio, `run_code` uses a persistent Jupyter kernel in your VBT environment. Your client's
approval controls let you decide which code the assistant runs. The setup guide below covers
installation and client configuration.

`get_environment` reports the Python interpreter and the Python and VBT versions, so an assistant
can check its setup first. The first search after starting the server loads the knowledge assets,
which takes the most time, and later searches reuse them. When embeddings for some documents are
missing, search ranks them by keywords instead of generating the embeddings first. Tools support
token budgets and pagination, so the assistant can request a focused result and read more when
needed.

## Tools \[#tools]

| Tool                                                                 | What it does                                                                                    |
| -------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| `search`                                                             | Ranks documentation, API, examples, and community answers for a query                           |
| `find`                                                               | Returns the material about specific objects, such as `vbt.PF.from_signals`                      |
| `resolve_refnames`                                                   | Turns names like `vbt.Data` into fully qualified names                                          |
| `get_page`, `get_message`, `get_message_block`, `get_message_thread` | Read a page, a message, consecutive messages from one author, or a whole discussion by its link |
| `find_concepts`, `get_concept`                                       | Search the concept map and see how concepts relate                                              |
| `get_attrs`, `get_source`                                            | List an object's attributes, read its source code                                               |
| `list_skills`, `get_skill`                                           | Read the agent skills that ship with VBT                                                        |
| `run_code`                                                           | Runs Python with VBT in a persistent Jupyter kernel                                             |
| `get_environment`                                                    | Reports the Python interpreter and the Python and VBT versions                                  |

Every tool also runs from the terminal, as in `vbt mcp search "rolling Sharpe ratio"`, and from
Python through `vbt.mcp`. The server exposes these functions as MCP tools, including the tools that
read documentation. You can also use them from the
[AI research assistant](/features/ai/ai-research-assistant/) inside Python.

!!! info "Guide"
    The members-only [Using AI](https://members.vectorbt.pro/using-ai/) guide sets up the server for each client,
    serves it over HTTP, and lists prompts to try.


## Related pages

*   [AI research assistant](/features/ai/ai-research-assistant/): Chat with an assistant grounded in VBT docs and examples, with tools and reasoning
*   [Knowledge search](/features/ai/knowledge-search/): Search docs, API, examples, and community answers with keyword and embedding ranking
*   [AI](/features/ai/): Get help with Python backtests, search VBT knowledge, and connect your coding assistant
*   [Developer tools](/features/tooling/developer-tools/): Search the API, read source, draw reference graphs, and extend classes with factories