Model Context Protocol (MCP) is a protocol that allows you to create agents that can interact with each other.
MCP is a protocol that allows you to create agents that can interact with each other.
$ npm install$ npm install -g @nestjs/cli$ nvm use 18mkdir products cd products
npm init -y
npm install @modelcontextprotocol/sdk zod npm install -D @types/node typescript
mkdir src touch src/index.ts
{
"type": "module",
"bin": {
"weather": "./build/index.js"
},
"scripts": {
"build": "tsc && chmod 755 build/index.js"
},
"files": [
"build"
],
}{
"compilerOptions": {
"target": "ES2022",
"module": "Node16",
"moduleResolution": "Node16",
"outDir": "./build",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new McpServer({
name: "products",
version: "1.0.0",
});
server.tool("fetch-product", "Get product model", async (input) => {
const product = [
{
"title": "Iphone 14",
"brand": "Apple",
"model": "Iphone 14",
"color": "red",
},
{
"title": "Iphone 14 Pro",
"brand": "Apple",
"model": "Iphone 14 Pro",
"color": "black",
},
{
"title": "Iphone 13 Pro Max",
"brand": "Apple",
"model": "Iphone 13 Pro Max",
"color": "yellow",
},
{
"title": "Iphone 12 Pro Max",
"brand": "Apple",
"model": "Iphone 12 Pro Max",
"color": "green",
},
{
"title": "Iphone 14 Pro Max",
"brand": "Apple",
"model": "Iphone 14 Pro Max",
"color": "white",
},
];
return {
content: [
{
type: "text",
text: JSON.stringify(product),
}
]
}
});
const transport = new StdioServerTransport();
await server.connect(transport);$ npm run build$ cd products/src/
$ npx -y @modelcontextprotocol/inspector npx -y tsx index.ts🔍 MCP Inspector is up and running at http://127.0.0.1:# 🚀
1.- Open IDE Trae and selected in the right side in the configuration icon selected MCP. 2.- In the List selected "+ Add" button and selected Configuration Manually, then selected "Raw Config (JSON)". 3.- In the Text add new json item example:
{
"products": {
"command": "node",
"args": [
"[Your-path]/index.js"
]
}
}4.- Validate and save the configuration. 5.- Create new Agent and selected the MCP configuration.
In the chat selected @Agent and selected the mcp configuration.