https://github.com/dylibso/mcpx-anthropic-node
Anthropic node support for MCPX
https://github.com/dylibso/mcpx-anthropic-node
Last synced: about 1 year ago
JSON representation
Anthropic node support for MCPX
- Host: GitHub
- URL: https://github.com/dylibso/mcpx-anthropic-node
- Owner: dylibso
- License: bsd-3-clause
- Created: 2025-01-22T22:20:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-08T17:09:51.000Z (about 1 year ago)
- Last Synced: 2025-04-08T18:25:10.255Z (about 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 90.8 KB
- Stars: 4
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MCPX Anthropic Client
This library allows you connect your [Anthropic](https://www.anthropic.com/) models to
[mcp.run](https://mcp.run) and expose your installed servlets as tools which can be
invoked in process (without spinning up many server processes).
## Usage
### Install
You just need the mcpx-anthropic library and the anthropic library (if you don't already have it).
```
npm install @dylibso/mcpx-anthropic @anthropic-ai/sdk
```
To get an mcp.run session id, run this command and follow the instructions:
```
npx --yes -p @dylibso/mcpx@latest gen-session
```
### Code
This package exports a message driver designed to wrap the Anthropic `createMessage` API:
```typescript
import Anthropic from "@anthropic-ai/sdk";
import createDriver from "@dylibso/mcpx-anthropic"
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY
})
const mcpx = await createDriver({
anthropic,
sessionId: process.env.MCP_RUN_SESSION_ID,
})
const messages = [];
// call any tool compatible api, e.g chat completion:
// let's ask it to evalute some javascript. If you have
// this tool installed: https://www.mcp.run/bhelx/eval-js it should
// determine and use this to evaluate it in a sandbox
messages.push({
role: 'user',
content: `
Write a djb2hash function in javascript and evalute it on the string "Hello, World!"
`
});
// this will automatically process all tool calls
// until there are none left
const response = await mcpx.createMessage({
max_tokens: 1024,
messages,
model: 'claude-3-5-sonnet-latest',
});
console.log(response.content)
//=> The DJB2 hash of the string "Hello, World!" is `-1763540338`.
```
### Examples
* [Example chat application](examples/chat)