Skip to main content
Glama
Vanshika-Rana

Payman AI Documentation MCP Server

get-code-examples

Retrieve Node.js or Python code examples for PaymanAI integration features to help developers implement specific functionality in their projects.

Instructions

Get Node.js or Python code examples for PaymanAI integration

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
featureYesThe feature or functionality you need code examples for
languageNoProgramming language (nodejs or python)nodejs

Implementation Reference

  • The handler function that implements the get-code-examples tool. It searches documentation for relevant code blocks in the specified language matching the feature, extracts them using regex, and formats them into a response.
    async ({ feature, language }) => {
    	log(`Getting ${language} code example for: "${feature}"`);
    
    	const potentialTopics = Object.entries(pathMap)
    		.filter(
    			([topic]) =>
    				topic.toLowerCase().includes(feature.toLowerCase()) ||
    				topicMetadata[topic].title
    					.toLowerCase()
    					.includes(feature.toLowerCase())
    		)
    		.map(([topic]) => topic);
    
    	const topicsToSearch =
    		potentialTopics.length > 0 ? potentialTopics : Object.keys(pathMap);
    
    	const examplesPromises = topicsToSearch.map(async (topic) => {
    		const path = pathMap[topic];
    		const content = await fetchDocMarkdown(path);
    
    		const codeBlockRegex =
    			language === "nodejs"
    				? /```(?:javascript|typescript|js|nodejs|node)([\s\S]*?)```/g
    				: /```(?:python|py)([\s\S]*?)```/g;
    
    		const matches = [...content.matchAll(codeBlockRegex)];
    
    		const relevantBlocks = matches
    			.map((match) => match[1].trim())
    			.filter(
    				(code) =>
    					code.toLowerCase().includes(feature.toLowerCase()) ||
    					content
    						.substring(
    							Math.max(0, content.indexOf(code) - 300),
    							content.indexOf(code)
    						)
    						.toLowerCase()
    						.includes(feature.toLowerCase())
    			);
    
    		if (relevantBlocks.length === 0) return null;
    
    		return {
    			topic,
    			title: topicMetadata[topic].title,
    			examples: relevantBlocks,
    		};
    	});
    
    	const allExamples = (await Promise.all(examplesPromises)).filter(
    		Boolean
    	);
    
    	if (allExamples.length === 0) {
    		return {
    			content: [
    				{
    					type: "text",
    					text: `No ${language} code examples found for "${feature}". Try searching for a different feature or check the full documentation using get-documentation.`,
    				},
    			],
    		};
    	}
    
    	let responseText = `# ${language.toUpperCase()} Code Examples for "${feature}"\n\n`;
    
    	allExamples.forEach((topicExamples) => {
    		if (!topicExamples) return;
    
    		responseText += `## From ${topicExamples.title}\n\n`;
    
    		topicExamples.examples.forEach((code, index) => {
    			responseText += `### Example ${index + 1}\n\n`;
    			responseText += `\`\`\`${
    				language === "nodejs" ? "javascript" : "python"
    			}\n${code}\n\`\`\`\n\n`;
    		});
    
    		responseText += `*For more context, check the full documentation: use get-documentation with topic "${topicExamples.topic}".*\n\n---\n\n`;
    	});
    
    	return {
    		content: [
    			{
    				type: "text",
    				text: responseText,
    			},
    		],
    	};
    }
  • Zod schema defining the input parameters for the tool: feature (required string) and language (optional enum defaulting to nodejs).
    	feature: z
    		.string()
    		.describe(
    			"The feature or functionality you need code examples for"
    		),
    	language: z
    		.enum(["nodejs", "python"])
    		.default("nodejs")
    		.describe("Programming language (nodejs or python)"),
    },
  • src/index.ts:291-396 (registration)
    The server.tool call that registers the get-code-examples tool with the MCP server, providing name, description, input schema, and handler function.
    server.tool(
    	"get-code-examples",
    	"Get Node.js or Python code examples for PaymanAI integration",
    	{
    		feature: z
    			.string()
    			.describe(
    				"The feature or functionality you need code examples for"
    			),
    		language: z
    			.enum(["nodejs", "python"])
    			.default("nodejs")
    			.describe("Programming language (nodejs or python)"),
    	},
    	async ({ feature, language }) => {
    		log(`Getting ${language} code example for: "${feature}"`);
    
    		const potentialTopics = Object.entries(pathMap)
    			.filter(
    				([topic]) =>
    					topic.toLowerCase().includes(feature.toLowerCase()) ||
    					topicMetadata[topic].title
    						.toLowerCase()
    						.includes(feature.toLowerCase())
    			)
    			.map(([topic]) => topic);
    
    		const topicsToSearch =
    			potentialTopics.length > 0 ? potentialTopics : Object.keys(pathMap);
    
    		const examplesPromises = topicsToSearch.map(async (topic) => {
    			const path = pathMap[topic];
    			const content = await fetchDocMarkdown(path);
    
    			const codeBlockRegex =
    				language === "nodejs"
    					? /```(?:javascript|typescript|js|nodejs|node)([\s\S]*?)```/g
    					: /```(?:python|py)([\s\S]*?)```/g;
    
    			const matches = [...content.matchAll(codeBlockRegex)];
    
    			const relevantBlocks = matches
    				.map((match) => match[1].trim())
    				.filter(
    					(code) =>
    						code.toLowerCase().includes(feature.toLowerCase()) ||
    						content
    							.substring(
    								Math.max(0, content.indexOf(code) - 300),
    								content.indexOf(code)
    							)
    							.toLowerCase()
    							.includes(feature.toLowerCase())
    				);
    
    			if (relevantBlocks.length === 0) return null;
    
    			return {
    				topic,
    				title: topicMetadata[topic].title,
    				examples: relevantBlocks,
    			};
    		});
    
    		const allExamples = (await Promise.all(examplesPromises)).filter(
    			Boolean
    		);
    
    		if (allExamples.length === 0) {
    			return {
    				content: [
    					{
    						type: "text",
    						text: `No ${language} code examples found for "${feature}". Try searching for a different feature or check the full documentation using get-documentation.`,
    					},
    				],
    			};
    		}
    
    		let responseText = `# ${language.toUpperCase()} Code Examples for "${feature}"\n\n`;
    
    		allExamples.forEach((topicExamples) => {
    			if (!topicExamples) return;
    
    			responseText += `## From ${topicExamples.title}\n\n`;
    
    			topicExamples.examples.forEach((code, index) => {
    				responseText += `### Example ${index + 1}\n\n`;
    				responseText += `\`\`\`${
    					language === "nodejs" ? "javascript" : "python"
    				}\n${code}\n\`\`\`\n\n`;
    			});
    
    			responseText += `*For more context, check the full documentation: use get-documentation with topic "${topicExamples.topic}".*\n\n---\n\n`;
    		});
    
    		return {
    			content: [
    				{
    					type: "text",
    					text: responseText,
    				},
    			],
    		};
    	}
    );

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

B3.1/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states what the tool does without behavioral details. It lacks information on permissions, rate limits, response format, or whether this is a read-only operation, leaving significant gaps for a tool that likely queries external resources.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It is appropriately sized and front-loaded, directly stating the tool's purpose without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, no annotations, no output schema), the description is minimally adequate. It covers the basic purpose but lacks behavioral context and usage guidelines, making it incomplete for optimal agent understanding without additional structured data.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents both parameters. The description adds no additional meaning beyond implying that 'feature' relates to PaymanAI integration and 'language' specifies code examples, which is already clear from the schema. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get') and resource ('code examples for PaymanAI integration') with specific scope ('Node.js or Python'). It distinguishes from siblings by focusing on code examples rather than documentation or problem-solving, though it doesn't explicitly contrast with each sibling tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'get-documentation' or 'search-documentation'. The description implies usage for code examples but offers no explicit context, prerequisites, or exclusions for tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.