Skip to content

Commit db1c7bc

Browse files
authored
Mcp (#175)
* chore: upgraded packages * feat: mcp * feat: set enviroment vars * fix: various * fix: various * fix: updates * fix: updates
1 parent b103f41 commit db1c7bc

35 files changed

+1608
-514
lines changed

.cspell.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"ignorePaths": [
1111
"node_modules",
1212
"./src/docs/src/content/docs/03-apidocs",
13-
"./src/ax/dsp/stopwords.ts"
13+
"./src/ax/dsp/stopwords.ts",
14+
"./src/examples/*.ts"
1415
]
1516
}

.cspell/project-words.txt

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Logprob
4242
logprobs
4343
Logprobs
4444
Macbook
45+
MCPHTTP
4546
minilm
4647
Mixtral
4748
modelinfo

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Use Ax and get an end-to-end streaming, multi-modal DSPy framework with agents a
1212
- Prompts auto-generated from simple signatures
1313
- Full native end-to-end streaming
1414
- Build Agents that can call other agents
15+
- Built in MCP, Model Context Protocol support
1516
- Convert docs of any format to text
1617
- RAG, smart chunking, embedding, querying
1718
- Works with Vercel AI SDK
@@ -402,6 +403,43 @@ The load balancer is ideal for high availability while the router is perfect whe
402403

403404
You can also use the balancer and the router together either the multiple balancers can be used with the router or the router can be used with the balancer.
404405

406+
## Model Context Protocol (MCP)
407+
408+
Ax provides seamless integration with the Model Context Protocol (MCP), allowing your agents to access external tools, and resources through a standardized interface.
409+
410+
### Using AxMCPClient
411+
412+
The `AxMCPClient` allows you to connect to any MCP-compatible server and use its capabilities within your Ax agents:
413+
414+
```typescript
415+
import { AxMCPClient, AxMCPStdioTransport } from '@ax-llm/ax'
416+
417+
// Initialize an MCP client with a transport
418+
const transport = new AxMCPStdioTransport({
419+
command: 'npx',
420+
args: ['-y', '@modelcontextprotocol/server-memory'],
421+
})
422+
423+
// Create the client with optional debug mode
424+
const client = new AxMCPClient(transport, { debug: true })
425+
426+
// Initialize the connection
427+
await client.init()
428+
429+
// Use the client's functions in an agent
430+
const memoryAgent = new AxAgent({
431+
name: 'MemoryAssistant',
432+
description: 'An assistant with persistent memory',
433+
signature: 'input, userId -> response',
434+
functions: [client], // Pass the client as a function provider
435+
})
436+
437+
// Or use the client with AxGen
438+
const memoryGen = new AxGen('input, userId -> response', {
439+
functions: [client]
440+
})
441+
```
442+
405443
## Vercel AI SDK Integration
406444

407445
Install the ax provider package
@@ -631,6 +669,7 @@ OPENAI_APIKEY=openai_key npm run tsx ./src/examples/marketing.ts
631669
| docker.ts | Use the docker sandbox to find files by description |
632670
| prime.ts | Using field processors to process fields in a prompt |
633671
| simple-classify.ts | Use a simple classifier to classify stuff |
672+
| mcp-client.ts | Example of using an MCP server with Ax |
634673

635674
## Our Goal
636675

0 commit comments

Comments
 (0)