如何用 40 行 Node 程式碼檢視 MCP 伺服器的工具描述
How to Review Your MCP Server’s Tool Descriptions in 40 Lines of Node
MCP 伺服器可用一段 40 行的 Node 程式碼匯出工具描述,方便檢視並找出過時或不一致的內容。程式會從工具檔案擷取描述,並以 JSON 格式輸出;更新描述有助智能體可靠執行任務。
How to Review Your MCP Server’s Tool Descriptions
MCP servers rely heavily on accurate and up-to-date tool descriptions. If these descriptions are outdated or inconsistent, your agents may fail to execute tasks correctly. Here’s how you can efficiently review and update them using a 40-line Node script.
The Problem
Tool descriptions in MCP servers often become outdated or inconsistent over time. This can lead to:
- Agents failing to execute tasks correctly.
- Miscommunication between tools and agents.
- Difficulty in maintaining and scaling your MCP server.
The Solution
A simple Node script can help you dump and review your tool descriptions in a structured format. This script:
- Extracts tool descriptions from your MCP server.
- Formats them for easy review.
- Helps you identify inconsistencies or outdated information.
Example Script
Here’s a snippet of the script:
const fs = require('fs');
const path = require('path');
function dumpToolDescriptions(serverPath) {
const toolsDir = path.join(serverPath, 'tools');
const toolDescriptions = [];
fs.readdirSync(toolsDir).forEach(file => {
const filePath = path.join(toolsDir, file);
const content = fs.readFileSync(filePath, 'utf8');
const description = extractDescription(content);
toolDescriptions.push({ file, description });
});
return toolDescriptions;
}
function extractDescription(content) {
// Logic to extract description from content
return content.match(/description:\s*(.*)/s)?.[1].trim() || 'No description found.';
}
const serverPath = './your-mcp-server-path';
const descriptions = dumpToolDescriptions(serverPath);
console.log(JSON.stringify(descriptions, null, 2));
How to Use It
- Place the script in your MCP server directory.
- Run it to generate a JSON output of all tool descriptions.
- Review the output for inconsistencies or outdated information.
Why This Matters
Tool descriptions are critical for the functionality of your MCP server. By ensuring they are accurate and up-to-date, you ensure that your agents can perform tasks reliably and efficiently.
Next Steps
- Update any outdated or inconsistent descriptions.
- Share this script with your team to maintain consistency.
Have you encountered similar issues with your MCP server? How do you keep your tool descriptions up-to-date? Let me know in the comments!
來源:DEV Community · dev.to