MCP Quickstart

Run your first MCP workflow in 5 minutes.

Prerequisites

  • RelayPlane SDK installed (npm install @relayplane/sdk)
  • An MCP server URL (or use our test server for this example)

Basic Example

This example shows a workflow that extracts a company name using AI, then looks it up via an MCP tool:

1import { relay } from '@relayplane/sdk'
2
3// Configure providers and MCP servers
4relay.configure({
5 providers: {
6 openai: { apiKey: process.env.OPENAI_API_KEY! }
7 },
8 mcp: {
9 servers: {
10 demo: { url: 'https://mcp-demo.relayplane.com' }
11 }
12 }
13})
14
15// Create workflow with AI + MCP steps
16const workflow = relay
17 .workflow('company-lookup')
18 // Step 1: Extract company name (AI step)
19 .step('extract')
20 .with('openai:gpt-4o')
21 .prompt('Extract the company name from this email: {{input.email}}. Return just the name.')
22 // Step 2: Look up company (MCP step)
23 .step('lookup')
24 .mcp('demo:getCompanyInfo')
25 .params({ companyName: '{{extract.output}}' })
26 .depends('extract')
27 // Step 3: Summarize (AI step)
28 .step('summarize')
29 .with('openai:gpt-4o')
30 .depends('lookup')
31 .prompt('Write a brief summary of this company: {{lookup.output}}')
32
33// Run the workflow
34const result = await workflow.run({
35 email: 'Looking forward to our meeting! - John from Acme Corp'
36})
37
38if (result.success) {
39 console.log('Company:', result.steps.extract)
40 console.log('Info:', result.steps.lookup)
41 console.log('Summary:', result.steps.summarize)
42}

Expected Output

1{
2 "success": true,
3 "steps": {
4 "extract": "Acme Corp",
5 "lookup": {
6 "name": "Acme Corp",
7 "industry": "Technology",
8 "employees": 500,
9 "founded": 2015
10 },
11 "summarize": "Acme Corp is a technology company founded in 2015 with approximately 500 employees..."
12 }
13}

Step by Step

1. Configure MCP Servers

Add MCP servers to your relay.configure() call:

1relay.configure({
2 mcp: {
3 servers: {
4 crm: { url: 'https://mcp.salesforce.com' },
5 github: { url: 'https://mcp.github.com' },
6 slack: { url: 'https://mcp.slack.com' }
7 }
8 }
9})

2. Add MCP Steps

Use .mcp() instead of .with() for MCP steps:

1.step('lookup')
2.mcp('crm:searchCompany')
3.params({ name: '{{extract.output}}' })
4.depends('extract')

3. Pass Parameters

Use .params() to pass tool parameters with interpolation:

1.params({
2 name: '{{extract.output}}', // From previous step
3 type: '{{input.searchType}}', // From workflow input
4 limit: 10 // Static value
5})
MCP steps can depend on AI steps and vice versa. This lets you build powerful workflows that combine AI reasoning with external API calls.

Error Handling

MCP errors are handled the same way as AI step errors:

1const result = await workflow.run(input)
2
3if (!result.success) {
4 if (result.error?.stepName === 'lookup') {
5 console.error('MCP tool failed:', result.error.message)
6 // Handle MCP-specific errors
7 }
8}

Next Steps