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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@metorial/mcp-sdk-utils

v2.0.0

Published

MCP SDK utilities for Metorial. Provides common utilities and helpers for MCP (Model Context Protocol) integration with AI SDK frameworks.

Readme

@metorial/mcp-sdk-utils

MCP SDK utilities for Metorial. Provides common utilities and helpers for MCP (Model Context Protocol) integration with AI SDK frameworks.

Installation

npm install @metorial/mcp-sdk-utils
# or
yarn add @metorial/mcp-sdk-utils
# or
pnpm add @metorial/mcp-sdk-utils
# or
bun add @metorial/mcp-sdk-utils

Usage

Basic AI SDK Integration

import { metorialAiSdk } from '@metorial/mcp-sdk-utils';
import { Metorial } from '@metorial/sdk';
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';

// Initialize Metorial
let metorial = new Metorial({
  apiKey: 'your-metorial-api-key'
});

// Use with AI SDK
metorial.withProviderSession(
  metorialAiSdk,
  {
    serverDeployments: ['your-server-deployment-id']
  },
  async session => {
    let result = await generateText({
      model: openai('gpt-4o'),
      prompt: 'Summarize the latest news about AI developments',
      maxSteps: 10,
      tools: session.tools
    });

    console.log(result.text);
  }
);

Advanced Tool Usage

import { metorialAiSdk } from '@metorial/mcp-sdk-utils';
import { Metorial } from '@metorial/sdk';
import { generateText, streamText } from 'ai';
import { openai } from '@ai-sdk/openai';

let metorial = new Metorial({
  apiKey: 'your-metorial-api-key'
});

// Streaming with tools
metorial.withProviderSession(
  metorialAiSdk,
  {
    serverDeployments: ['your-server-deployment-id']
  },
  async session => {
    let { textStream } = await streamText({
      model: openai('gpt-4o'),
      prompt: 'Research the latest developments in quantum computing',
      maxSteps: 15,
      tools: session.tools
    });

    for await (let chunk of textStream) {
      process.stdout.write(chunk);
    }
  }
);

Custom Tool Configuration

import { metorialAiSdk } from '@metorial/mcp-sdk-utils';
import { Metorial } from '@metorial/sdk';
import { generateText } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';

let metorial = new Metorial({
  apiKey: 'your-metorial-api-key'
});

// Configure session with specific tools
metorial.withProviderSession(
  metorialAiSdk,
  {
    serverDeployments: ['your-server-deployment-id'],
    // Optional: Filter specific tools
    toolFilter: tool => tool.name.startsWith('search')
  },
  async session => {
    console.log(
      'Available tools:',
      session.tools.map(t => t.name)
    );

    let result = await generateText({
      model: anthropic('claude-3-sonnet-20240229'),
      prompt: 'Find information about renewable energy trends',
      maxSteps: 8,
      tools: session.tools
    });

    console.log('Result:', result.text);
  }
);

Error Handling

import { metorialAiSdk } from '@metorial/mcp-sdk-utils';
import { Metorial } from '@metorial/sdk';
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';

let metorial = new Metorial({
  apiKey: 'your-metorial-api-key'
});

try {
  await metorial.withProviderSession(
    metorialAiSdk,
    {
      serverDeployments: ['your-server-deployment-id']
    },
    async session => {
      let result = await generateText({
        model: openai('gpt-4o'),
        prompt: 'Analyze the current market trends',
        maxSteps: 10,
        tools: session.tools
      });

      return result.text;
    }
  );
} catch (error) {
  if (error.code === 'TOOL_EXECUTION_ERROR') {
    console.error('Tool execution failed:', error.message);
  } else if (error.code === 'SESSION_ERROR') {
    console.error('Session error:', error.message);
  } else {
    console.error('Unexpected error:', error);
  }
}

React Component Integration

import { metorialAiSdk } from '@metorial/mcp-sdk-utils';
import { Metorial } from '@metorial/sdk';
import { useChat } from 'ai/react';
import { openai } from '@ai-sdk/openai';

function ChatComponent() {
  let metorial = new Metorial({
    apiKey: 'your-metorial-api-key'
  });

  let { messages, input, handleInputChange, handleSubmit, isLoading } = useChat({
    api: '/api/chat',
    body: {
      metorialConfig: {
        provider: metorialAiSdk,
        serverDeployments: ['your-server-deployment-id']
      }
    }
  });

  return (
    <div>
      <div className="messages">
        {messages.map(message => (
          <div key={message.id}>
            <strong>{message.role}:</strong> {message.content}
          </div>
        ))}
      </div>

      <form onSubmit={handleSubmit}>
        <input
          value={input}
          onChange={handleInputChange}
          placeholder="Ask me anything..."
          disabled={isLoading}
        />
        <button type="submit" disabled={isLoading}>
          Send
        </button>
      </form>
    </div>
  );
}

API Route Handler

// pages/api/chat.ts
import { metorialAiSdk } from '@metorial/mcp-sdk-utils';
import { Metorial } from '@metorial/sdk';
import { openai, streamText } from 'ai';
import { NextRequest } from 'next/server';

export async function POST(req: NextRequest) {
  let { messages, metorialConfig } = await req.json();

  let metorial = new Metorial({
    apiKey: process.env.METORIAL_API_KEY!
  });

  return metorial.withProviderSession(
    metorialAiSdk,
    {
      serverDeployments: metorialConfig.serverDeployments
    },
    async session => {
      let { textStream } = await streamText({
        model: openai('gpt-4o'),
        messages,
        maxSteps: 10,
        tools: session.tools
      });

      return textStream;
    }
  );
}

Tool Discovery and Inspection

import { metorialAiSdk } from '@metorial/mcp-sdk-utils';
import { Metorial } from '@metorial/sdk';

let metorial = new Metorial({
  apiKey: 'your-metorial-api-key'
});

// Inspect available tools
metorial.withProviderSession(
  metorialAiSdk,
  {
    serverDeployments: ['your-server-deployment-id']
  },
  async session => {
    console.log('Available tools:');
    session.tools.forEach(tool => {
      console.log(`- ${tool.name}: ${tool.description}`);
      if (tool.function?.parameters) {
        console.log(`  Parameters:`, tool.function.parameters);
      }
    });

    // Test a specific tool
    let searchTool = session.tools.find(t => t.name === 'searchContext');
    if (searchTool) {
      let result = await searchTool.call({
        query: 'metorial AI tools',
        maxResults: 3
      });
      console.log('Tool test result:', result);
    }
  }
);

API Reference

metorialAiSdk

The main integration function that provides MCP tools to AI SDK frameworks.

Usage: Pass to metorial.withProviderSession() as the provider parameter.

Returns: Session object with tools compatible with AI SDK.

Session Object

The session object provides:

  • tools: Array of MCP tools compatible with AI SDK
  • callTools(toolCalls): Function to execute tool calls

Tool Object

Each tool in the session has:

  • name: Tool name
  • description: Tool description
  • function: Tool function definition with parameters
  • call(args): Function to call the tool directly

License

MIT License - see LICENSE file for details.