Build remote MCP tools using MCP-Nest: A Quick Guide
We at Rekog developed the
@rekog/mcp-nest
package to expose our tools and agents over the network. This enables our customers to build their own AI Agents that utilize our tooling and allows them to use these tools from various AI clients such as Claude Desktop, custom clients, and more. Currently, we expose our clients in our web application and in Slack.The package has been well-received, with over 10,000 downloads and code contributions from many individual contributors. It has gradually built out its functionality to cover most of the MCP Spec.
Remote tools over the network offer a significant advantage over the more common stdio
transport type used by many MCP tools. By publishing MCP tools over the network, you can continuously improve them and add new features without requiring users to update their client applications (which is often difficult to enforce).
Below, we explain how to quickly use the @rekog/mcp-nest
package to build a custom counting tool and integrate it with Claude Desktop. The code for this example is available at rekog-labs/mcp-nest-getting-started.
A Counting Tool: Addressing LLM Limitations
Large Language Models (LLMs) can struggle with seemingly simple tasks. A popular example is counting the occurrences of the letter 'R' in the word "strawberry". This difficulty arises because LLMs process text as tokens and their probability distributions, rather than "seeing" individual characters as humans do.
However, with a simple counting tool, we can help LLMs overcome this limitation!
Step 1: Setting Up the NestJS Project
First, make sure you have Node.js and npm installed, then create a new NestJS project:
npm i -g @nestjs/cli
nest new counting-tool
cd counting-tool
Now install the MCP-Nest module:
npm install @rekog/mcp-nest reflect-metadata @modelcontextprotocol/sdk@1.11.0 zod
Step 2: Creating Our Counting Tool
Let's create a simple tool class that can count characters in text. Create a new file called src/counting.tool.ts
:
// src/counting.tool.ts
import { Injectable } from '@nestjs/common';
import { Tool, Context } from '@rekog/mcp-nest';
import { z } from 'zod';
@Injectable()
export class CountingTool {
constructor() {}
@Tool({
name: 'count-characters',
description: 'Counts occurrences of a specific character in text',
parameters: z.object({
text: z.string().describe('The text to analyze'),
character: z.string().describe('The character to count'),
}),
})
async countCharacters({ text, character }, context: Context) {
let count = 0;
// Simple counting logic that's 100% accurate
for (let i = 0; i < text.length; i++) {
if (text[i] === character) {
count++;
}
}
return {
content: [
{
type: 'text',
text: `There are ${count} occurrences of '${character}' in the text.`
}
]
};
}
}
Step 3: Setting Up the Module
Now update your src/app.module.ts
file to include the MCP module and your tool:
// src/app.module.ts
import { Module } from '@nestjs/common';
import { McpModule } from '@rekog/mcp-nest';
import { CountingTool } from './counting.tool';
@Module({
imports: [
McpModule.forRoot({
name: 'counting-tool-server',
version: '1.0.0',
}),
],
providers: [CountingTool],
})
export class AppModule {}
That's it! With this simple setup, you've created an MCP server that Claude can use to count characters accurately.
Step 4: Running the Server
Start your MCP server with:
npm run start
Step 5: Connecting to Claude Desktop
To connect your tool to Claude Desktop:
- Open Claude Desktop
- Go to Settings > Developer > Edit Config
- Add your MCP server to the configuration:
To use the tools exposed by the server you need to use the mcp-proxy
and use the server URL, as shown below:
{
"mcpServers": {
"counting": {
"command": "mcp-proxy",
"args": [
"http://localhost:3000/sse"
]
}
}
}
NOTE:
mcp-proxy
(repo) enables Claude Desktop (which currenlty supports only the stdio transport of the MCP spec) to connect to your MCP Server via HTTP+SSE protocol by translating between the two transport protocols.
Restart Claude Desktop, and your tool will be available!
Testing It Out
Now you can ask Claude: "How many 'R's are in 'strawberry'?"
Claude will use the counting tool to get to the correct answer: 3!
Summary
The key takeaway is that while LLMs are incredibly powerful, especially when giving them the right tools. MCP-Nest makes building these tools a breeze, especially if you're already familiar with NestJS.
For production environments, remember to consider security aspects such as authentication and authorization for your remote tools. @rekog/mcp-nest
supports NestJS Guards for this purpose.
We challenge you to try this out, explore further capabilities of @rekog/mcp-nest
, and see how it can transform your AI-clients!