MCP ExplorerExplorer

Mcpx Anthropic Node

@dylibsoon 9 months ago
6 BSD-3-Clause
FreeCommunity
AI Systems
Anthropic node support for MCPX

Overview

What is Mcpx Anthropic Node

mcpx-anthropic-node is a library that facilitates the connection between Anthropic models and MCPX, enabling users to expose installed servlets as tools that can be invoked in-process without the need for multiple server instances.

Use cases

Use cases include building chat applications, evaluating code snippets, and any scenario where dynamic interaction with AI models is required to enhance user experience.

How to use

To use mcpx-anthropic-node, install the library along with the Anthropic SDK using npm. Then, generate an MCPX session ID and utilize the provided code to create a message driver that wraps the Anthropic createMessage API.

Key features

Key features include seamless integration with Anthropic models, the ability to invoke servlets as tools, and a straightforward API for creating messages and processing tool calls efficiently.

Where to use

mcpx-anthropic-node can be used in various fields such as AI development, natural language processing, and any application that requires interaction with Anthropic models for tasks like chat completion or code evaluation.

Content

MCPX Anthropic Client

This library allows you connect your Anthropic models to
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:

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

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers