llm implementation of MCP for clients and servers.
Project description
llm-mcp
llm plugin
for creating MCP clients and servers.
Installation
pip install llm-mcp
MCP Servers
This package provides a bridge between MCP servers and the llm package,
allowing you to use MCP tools with LLM models. The bridge supports both stdio
and HTTP-based MCP servers and provides a synchronous interface that's safe to
use in any context, including Jupyter notebooks, FastAPI applications, and
more.
Command Line Usage
(todo)
Programmatic Usage
For programmatic usage, you can wrap MCP tools as llm.Tool objects:
import os
from llm import get_model
from llm_mcp import wrap_stdio, stdio
# convert stdio tool to llm tools
tools = wrap_stdio(stdio.ServerParameters(
command="npx",
args=["-y", "@wonderwhy-er/desktop-commander"],
))
# wrap_mcp(command string) equivalent to wrap_stdio(stdio.ServerParameters)
# from llm_mcp import wrap_mcp
# tools = wrap_mcp("npx -y @wonderwhy-er/desktop-commander")
# Use the tools with a model
model = get_model("gpt-4.1-nano")
response = model.chain(
f"Display the text found in the secret.txt file in {os.getcwd()}",
tools=tools,
)
print(response.text())
Output:
The text found in the secret.txt file is: "Why don't pelicans like to tip waiters?"
HTTP Servers
For HTTP-based MCP servers, use the HTTP bridge instead:
from llm import get_model
from llm_mcp import wrap_http, http
tools = wrap_http(http.ServerParameters("https://gitmcp.io/simonw/llm"))
# wrap_mcp(url) is equivalent to wrap_http(http.ServerParameters)
# from llm_mcp import wrap_mcp
# tools = wrap_mcp("https://gitmcp.io/simonw/llm")
model = get_model("gpt-4.1-nano")
response = model.chain(
"Search llm github for CHANGELOG and display 1 sentence summary of the latest entry.",
tools=tools,
)
print(response.text())
Output:
The latest entry in the changelog (version 0.26a0, dated 2025-05-13) introduces alpha support for tools in LLM, allowing models with tool capability (including the default OpenAI models) to execute Python functions as part of responding to a prompt, with usage available in both the command-line interface and Python API, and support for defining new tools via plugin hooks.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_mcp-0.0.2.tar.gz.
File metadata
- Download URL: llm_mcp-0.0.2.tar.gz
- Upload date:
- Size: 272.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
568f9ee62d5a5c72dba9ff536f57790f8fa7f29193a747f46bd64cb3e2cd0256
|
|
| MD5 |
f1ace6f91ca26a94acf1a60bd7f47a13
|
|
| BLAKE2b-256 |
5c7d39b067efc4746299a513dedd4cf8b79927210b7f952b7a766de6ad07d307
|
File details
Details for the file llm_mcp-0.0.2-py3-none-any.whl.
File metadata
- Download URL: llm_mcp-0.0.2-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b315ad6496b8fd6b91795d94638b1dc8250292744607a0ceff2707888fe2922a
|
|
| MD5 |
b288ced38287d30e3f58a39d822c185a
|
|
| BLAKE2b-256 |
a2d81851689f7d904e6505c16d508bb5ea04ac466a5d34162be0468f3802938e
|