npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@smithery/sdk

v0.0.13

Published

Connect language models to Model Context Protocols

Downloads

419

Readme

Smithery Typescript Framework npm version

Smithery is a Typescript framework that easily connects language models (LLMs) to Model Context Protocols (MCPs), allowing you to build agents that use resources and tools without being overwhelmed by JSON schemas.

⚠️ This repository is work in progress and in alpha. Not recommended for production use yet. ⚠️

Key Features

  • Connect to multiple MCPs with a single client
  • Adapters to transform MCP resposnes for OpenAI and Anthropic clients
  • Supports chaining tool calls until LLM completes

Quickstart

Installation

npm install @smithery/sdk

Usage

In this example, we'll connect use OpenAI client with Exa search capabilities.

npm install @smithery/mcp-exa

The following code sets up OpenAI and connects to an Exa MCP server. In this case, we're running the server locally within the same process, so it's just a simple passthrough.

import { MultiClient } from "@smithery/sdk"
import { OpenAIChatAdapter } from "@smithery/sdk/integrations/llm/openai"
import * as exa from "@smithery/mcp-exa"
import { OpenAI } from "openai"
import { createTransport } from "@smithery/sdk/registry"

const openai = new OpenAI()
const exaServer = exa.createServer({
  apiKey: process.env.EXA_API_KEY,
})

const sequentialThinking = await createTransport(
  "@modelcontextprotocol/server-sequential-thinking",
)
const client = new MultiClient()
await client.connectAll({
  exa: exaServer,
  sequentialThinking: sequentialThinking,
})

Now you can make your LLM aware of the available tools from Exa.

// Create an adapter
const adapter = new OpenAIChatAdapter(client)
const response = await openai.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "In 2024, did OpenAI release GPT-5?" }],
  // Pass the tools to OpenAI call
  tools: await adapter.listTools(),
})
// Obtain the tool outputs as new messages
const toolMessages = await adapter.callTool(response)

Using this, you can easily enable your LLM to call tools and obtain the results.

However, it's often the case where your LLM needs to call a tool, see its response, and continue processing output of the tool in order to give you a final response.

In this case, you have to loop your LLM call and update your messages until there are no more toolMessages to continue.

Example:

let messages = [
  {
    role: "user",
    content:
      "Deduce Obama's age in number of days. It's November 28, 2024 today. Search to ensure correctness.",
  },
]
const adapter = new OpenAIChatAdapter(client)

while (!isDone) {
  const response = await openai.chat.completions.create({
    model: "gpt-4o-mini",
    messages,
    tools: await adapter.listTools(),
  })
  // Handle tool calls
  const toolMessages = await adapter.callTool(response)

  // Append new messages
  messages.push(response.choices[0].message)
  messages.push(...toolMessages)
  isDone = toolMessages.length === 0
}

See a full example in the examples directory.

Troubleshooting

Error: ReferenceError: EventSource is not defined

This event means you're trying to use EventSource API (which is typically used in the browser) from Node. You'll have to install the following to use it:

npm install eventsource
npm install -D @types/eventsource

Patch the global EventSource object:

import EventSource from "eventsource"
global.EventSource = EventSource as any