You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -264,16 +264,17 @@ This stop indication won't completely halt the pipeline, but it will let it cont
264
264
265
265
The [Model Context Protocol (MCP)](https://github.com/model-context-protocol/specification) is an open standard for language models to interact with external tools and services. Rigging provides a client to connect to MCP-compliant servers.
266
266
267
-
Use the `rigging.tool.mcp` function, specifying the transport method (`stdio` or `sse`) and the connection parameters. It returns an *async context manager*.
267
+
### Using MCP Tools in Rigging
268
268
269
-
### Using `stdio` (Standard Input/Output)
269
+
Use the `rigging.mcp` function, specifying the transport method (`stdio` or `sse`) and the connection parameters. It returns an *async context manager*.
270
270
271
-
Connect to an MCP server launched as a local process that communicates over standard input/output.
272
-
273
-
```python
271
+
<CodeGroup>
272
+
```python Using "stdio" (Standard Input/Output)
274
273
import rigging as rg
275
274
276
-
# Example: Assuming 'my-mcp-server' is an executable that starts the MCP server
275
+
# Connect to an MCP server launched as a local process that communicates over standard input/output.
276
+
# (Assuming 'my-mcp-server' is an executable that starts the MCP server)
277
+
277
278
command ="my-mcp-server"
278
279
args = ["--port", "stdio"] # Example arguments
279
280
@@ -294,13 +295,11 @@ async with rg.mcp("stdio", command=command, args=args) as mcp_client:
294
295
295
296
```
296
297
297
-
### Using `sse` (Server-Sent Events)
298
-
299
-
Connect to an MCP server exposed via an HTTP endpoint using Server-Sent Events.
300
-
301
-
```python
298
+
```python Using "sse" (Server-Sent Events)
302
299
import rigging as rg
303
300
301
+
# Connect to an MCP server exposed via an HTTP endpoint using Server-Sent Events.
302
+
304
303
# URL of the MCP SSE endpoint
305
304
MCP_SSE_URL="http://localhost:8001/mcp"# Example URL
306
305
@@ -322,11 +321,109 @@ async with rg.mcp("sse", url=MCP_SSE_URL) as mcp_client:
322
321
323
322
The `mcp` context manager handles the connection, tool discovery, and communication with the MCP server. Inside the `async with` block, `mcp_client.tools` provides the list of discovered `Tool` objects ready to be used with `.using()`.
324
323
324
+
#### Example: Using Claude Code as a Rigging Tool
325
+
326
+
```python
327
+
import rigging as rg
328
+
329
+
asyncwith rg.mcp("stdio", command="claude", args=["mcp", "serve"]) as mcp_client:
.chat("Using tools, create a file_writer.py rigging tool that writes to a file.")
337
+
.using(*mcp_client.tools)
338
+
.run()
339
+
)
340
+
print(chat.conversation)
341
+
```
342
+
343
+
### Serving Tools with MCP
344
+
345
+
In addition to consuming tools from mcp servers, Rigging can **expose its own tools** as an MCP server. This allows you to write a singular tool implementation with the freedom to use it in other MCP-compliant clients, such as claude code.
346
+
347
+
The `rigging.as_mcp` function is the primary way to create an MCP server from your tools. It takes a list of Rigging `Tool` objects (or raw Python functions) and returns a `mcp.server.fastmcp.FastMCP` server instance, which you can then configure and run.
348
+
349
+
**How it works:**
350
+
1. You provide a list of tools to `as_mcp`.
351
+
2. It automatically converts raw functions into `rigging.Tool` objects.
352
+
3. For each tool, it creates a bridge that handles:
353
+
- Exposing the tool's name, description, and parameter schema.
354
+
- Calling your Python function when a request comes in.
355
+
- Converting your function's return value (including `rigging.Message` and `rigging.Stop`) into a format the MCP client can understand.
356
+
4. It returns a `FastMCP` server instance, ready to be run.
357
+
358
+
Let's create a server that exposes a `file_writer` tool.
359
+
360
+
**1. Define your tool(s) in a file (e.g., `file_writer.py`):**
361
+
362
+
```python
363
+
import rigging as rg
364
+
from typing import Annotated
365
+
366
+
@rg.tool()
367
+
defwrite_file(
368
+
filename: Annotated[str, "The name of the file to write to."],
369
+
content: Annotated[str, "The content to write to the file."],
370
+
) -> str:
371
+
"""
372
+
Writes content to a local file.
373
+
Creates the file if it doesn't exist, and overwrites it if it does.
374
+
"""
375
+
withopen(filename, "w") as f:
376
+
f.write(content)
377
+
returnf"Successfully wrote {len(content)} bytes to {filename}."
378
+
379
+
if__name__=="__main__":
380
+
# Create the MCP server instance from a list of tools
> Summarize the README file using the file_writer tool.
420
+
```
421
+
325
422
## Robopages
326
423
327
424
[Robopages](https://github.com/context-labs/robopages) is a framework for building and hosting tool-enabled "pages" or APIs. Rigging can dynamically fetch the available tools from a running Robopages server and make them available to your language model.
328
425
329
-
Use the `rigging.tool.robopages` function to connect to a Robopages endpoint and retrieve its tools.
426
+
Use the `rigging.robopages` function to connect to a Robopages endpoint and retrieve its tools.
0 commit comments