AI SDK

Connect Integrations to
AI SDK

Build advanced AI agents with AI SDK. Connect 600+ integrations, automate workflows, and deploy with ease using Metorial.

Back to AI SDK overview

Building Your First AI Agent

Let's build a practical AI agent that can interact with your GitHub repositories using Metorial and the AI SDK.

What We're Building

An AI assistant that can:

  • Search for repositories
  • Read file contents
  • Answer questions about your code
  • Summarize issues and pull requests

Step 1: Set Up Your Project

mkdir github-agent
cd github-agent
npm init -y
npm install @metorial/sdk @metorial/ai-sdk ai @ai-sdk/openai

Create a .env file:

METORIAL_API_KEY=your_metorial_key
METORIAL_SERVER_DEPLOYMENT_ID=your_deployment_id
OPENAI_API_KEY=your_openai_key

Step 2: Create Your Agent

Create agent.js:

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

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

async function askAgent(question) {
  return metorial.withProviderSession(
    metorialAiSdk,
    {
      serverDeployments: [process.env.METORIAL_SERVER_DEPLOYMENT_ID]
    },
    async session => {
      let result = await generateText({
        model: openai('gpt-4o'),
        prompt: question,
        maxSteps: 10,
        tools: session.tools
      });

      return result.text;
    }
  );
}

// Test it out
async function main() {
  let answer = await askAgent(
    'Find the README file in the metorial/websocket-explorer repository and summarize what the project does'
  );
  
  console.log('Answer:', answer);
}

main();

Step 3: Run Your Agent

node agent.js

Step 4: Add More Capabilities

Expand your agent with different queries:

async function main() {
  // Read a specific file
  let fileContent = await askAgent(
    'Show me the package.json from my main project repository'
  );
  console.log('File content:', fileContent);

  // Analyze issues
  let issues = await askAgent(
    'What are the most recent open issues in my repositories?'
  );
  console.log('Issues:', issues);

  // Code search
  let codeSearch = await askAgent(
    'Find all TypeScript files that import the Metorial SDK'
  );
  console.log('Search results:', codeSearch);
}

Step 5: Make It Interactive

Add a simple CLI interface:

import * as readline from 'readline';

let rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

async function chat() {
  rl.question('You: ', async (question) => {
    if (question.toLowerCase() === 'exit') {
      console.log('Goodbye!');
      rl.close();
      return;
    }

    try {
      let answer = await askAgent(question);
      console.log('Agent:', answer);
    } catch (error) {
      console.error('Error:', error.message);
    }

    chat(); // Continue the conversation
  });
}

console.log('GitHub Agent ready! Type "exit" to quit.');
chat();

Example Interactions

You: What repositories do I have?
Agent: You have 12 repositories including metorial-sdk, websocket-explorer, and ai-examples...

You: What's in the README of websocket-explorer?
Agent: The websocket-explorer is a tool for testing and debugging WebSocket connections...

You: Are there any open issues about authentication?
Agent: Yes, there are 2 open issues related to authentication: #42 discusses OAuth...

Next Steps

Now that you have a working agent, you can:

  • Add More Integrations: Connect Slack, email, calendars, etc.
  • Improve Context: Store conversation history for better responses
  • Add Memory: Use a database to remember past interactions
  • Create Workflows: Chain multiple tasks together
  • Deploy: Host your agent on a server or cloud platform

Tips for Better Agents

  • Clear System Prompts: Tell the AI what it should and shouldn't do
  • Appropriate maxSteps: Set based on task complexity
  • Error Handling: Always handle errors gracefully
  • Rate Limiting: Implement limits to avoid excessive API calls
  • Testing: Test with various inputs to ensure reliability

Your agent now has access to 600+ integrations through Metorial - the possibilities are endless!

AI SDK on Metorial

Connect Vercel AI SDK to Metorial and unlock instant access to over 600 integrations for your AI-powered applications. Our open-source, MCP-powered platform makes it effortless to add tools, APIs, and services to your AI SDK projects without writing complex integration code. With Metorial's TypeScript SDK, you can integrate calendars, databases, communication tools, and hundreds of other services in just a couple of lines of code. Whether you're building chatbots, AI assistants, or intelligent workflows with Vercel's AI SDK, Metorial eliminates integration headaches so you can focus on creating exceptional user experiences. Our developer-friendly approach means less time wrestling with authentication, API documentation, and maintenance—and more time innovating. Join developers who are shipping AI applications faster by letting Metorial handle the integration layer while you concentrate on what makes your app unique.

Connect anything. Anywhere.

Ready to build with Metorial?

Let's take your AI-powered applications to the next level, together.

About Metorial

Metorial provides developers with instant access to 600+ MCP servers for building AI agents that can interact with real-world tools and services. Built on MCP, Metorial simplifies agent tool integration by offering pre-configured connections to popular platforms like Google Drive, Slack, GitHub, Notion, and hundreds of other APIs. Our platform supports all major AI agent frameworks—including LangChain, AutoGen, CrewAI, and LangGraph—enabling developers to add tool calling capabilities to their agents in just a few lines of code. By eliminating the need for custom integration code, Metorial helps AI developers move from prototype to production faster while maintaining security and reliability. Whether you're building autonomous research agents, customer service bots, or workflow automation tools, Metorial's MCP server library provides the integrations you need to connect your agents to the real world.

Star us on GitHub