Skip to main content
Glama
Vanshika-Rana

Payman AI Documentation MCP Server

search-documentation

Find answers in Payman AI documentation by searching with specific queries to access relevant information for development tasks.

Instructions

Search through PaymanAI documentation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch term

Implementation Reference

  • src/index.ts:171-173 (registration)
    Registers the "search-documentation" tool with MCP server, specifying the tool name, description, input schema, and handler function.
    server.tool(
    	"search-documentation",
    	"Search through PaymanAI documentation",
  • Zod schema defining the input parameter 'query' as a string for the search term.
    {
    	query: z.string().describe("Search term"),
    },
  • Core handler function that implements the tool logic: fetches and caches documentation for all topics, searches each for the query, extracts the best matching section and surrounding context as excerpt, collects results, and returns formatted markdown response or topic suggestions if no matches.
    	async ({ query }) => {
    		log(`Searching for: "${query}"`);
    
    		const docsToSearch = Object.entries(pathMap).map(([topic, path]) => ({
    			topic,
    			path,
    			title: topicMetadata[topic].title,
    		}));
    
    		const searchPromises = docsToSearch.map(async (doc) => {
    			const content = await fetchDocMarkdown(doc.path);
    			const queryLower = query.toLowerCase();
    
    			if (content.toLowerCase().includes(queryLower)) {
    				const sections = content.split(/^#+\s+/m);
    				let bestSection = "";
    				let bestContext = "";
    
    				for (const section of sections) {
    					if (section.toLowerCase().includes(queryLower)) {
    						const lines = section.split("\n");
    						const sectionTitle = lines[0] || "";
    						const sectionContent = lines.slice(1).join("\n");
    
    						const index = sectionContent
    							.toLowerCase()
    							.indexOf(queryLower);
    						const start = Math.max(0, index - 150);
    						const end = Math.min(
    							sectionContent.length,
    							index + queryLower.length + 150
    						);
    						const excerpt =
    							(start > 0 ? "..." : "") +
    							sectionContent
    								.substring(start, end)
    								.replace(/\n+/g, " ") +
    							(end < sectionContent.length ? "..." : "");
    
    						bestSection = sectionTitle;
    						bestContext = excerpt;
    						break;
    					}
    				}
    
    				return {
    					title: doc.title,
    					topic: doc.topic,
    					section: bestSection,
    					excerpt: bestContext || content.substring(0, 200) + "...",
    				};
    			}
    			return null;
    		});
    
    		const searchResults = (await Promise.all(searchPromises)).filter(
    			Boolean
    		);
    
    		if (searchResults.length === 0) {
    			const possibleTopics = Object.entries(topicMetadata)
    				.filter(
    					([topic, meta]) =>
    						topic.includes(query.toLowerCase()) ||
    						meta.title.toLowerCase().includes(query.toLowerCase())
    				)
    				.map(([topic, meta]) => ({
    					topic,
    					title: meta.title,
    				}));
    
    			let suggestionText = "";
    			if (possibleTopics.length > 0) {
    				suggestionText =
    					"\n\nYou might be interested in these topics:\n\n" +
    					possibleTopics
    						.map(
    							(s) =>
    								`- ${s.title} (use get-documentation with topic "${s.topic}")`
    						)
    						.join("\n");
    			}
    
    			return {
    				content: [
    					{
    						type: "text",
    						text: `No results found for "${query}". Try a different search term.${suggestionText}`,
    					},
    				],
    			};
    		}
    
    		const formattedResults = searchResults
    			.map((r) => {
    				if (!r) return "";
    
    				const sectionHeading = r.section ? `### ${r.section}\n\n` : "";
    
    				return `## ${r.title}\n\n${sectionHeading}${r.excerpt}\n\n*For full documentation, use the get-documentation tool with topic "${r.topic}".*`;
    			})
    			.join("\n\n---\n\n");
    
    		return {
    			content: [
    				{
    					type: "text",
    					text: `# Search Results for "${query}"\n\n${formattedResults}`,
    				},
    			],
    		};
    	}
    );
  • Key helper utility for fetching and caching Markdown documentation content from PaymanAI docs site, heavily used by the search handler to load content for searching.
    async function fetchDocMarkdown(path: string): Promise<string> {
    	const now = Date.now();
    	const cachedDoc = documentCache.get(path);
    
    	if (cachedDoc && now - cachedDoc.timestamp < CACHE_TTL) {
    		log(`Using cached content for: ${path}`);
    		return cachedDoc.content;
    	}
    
    	try {
    		const url = `https://docs.paymanai.com${path}.md`;
    		log(`Fetching: ${url}`);
    
    		const response = await fetch(url);
    
    		if (!response.ok) {
    			throw new Error(`Failed to fetch: ${response.status}`);
    		}
    
    		const content = await response.text();
    		documentCache.set(path, { content, timestamp: now });
    
    		return content;
    	} catch (error) {
    		log(`Error fetching documentation: ${error}`);
    		return `Documentation content not available for path: ${path}.md\nError: ${
    			error instanceof Error ? error.message : String(error)
    		}`;
    	}
    }
  • Data structures defining available documentation topics, mappings from topics to doc paths, and metadata (titles, related topics) used by the search-documentation handler to iterate over docs and enrich results.
    const docTopics = [
    	"quickstart",
    	"playground",
    	"setup-and-installation",
    	"create-payees",
    	"send-payments",
    	"create-payee",
    	"search-payees",
    	"check-balances",
    	"bill-payment-agent",
    	"api-reference",
    	"api-keys",
    	"error-handling",
    ] as const;
    
    const pathMap: Record<string, string> = {
    	quickstart: "/overview/quickstart",
    	playground: "/overview/playground",
    	"setup-and-installation": "/sdks/setup-and-installation",
    	"create-payees": "/sdks/create-payees",
    	"send-payments": "/sdks/send-payments",
    	"create-payee": "/sdks/create-payee",
    	"search-payees": "/sdks/search-payees",
    	"check-balances": "/sdks/check-balances",
    	"bill-payment-agent": "/guides/bill-payment-agent",
    	"api-reference": "/api-reference/introduction",
    	"api-keys": "/api-reference/get-api-key",
    	"error-handling": "/api-reference/error-handling",
    };
    
    const topicMetadata: Record<
    	string,
    	{
    		title: string;
    		relatedTopics: string[];
    	}
    > = {
    	quickstart: {
    		title: "Quickstart Guide",
    		relatedTopics: ["setup-and-installation", "api-keys"],
    	},
    	playground: {
    		title: "API Playground",
    		relatedTopics: ["api-reference", "api-keys"],
    	},
    	"setup-and-installation": {
    		title: "Setup and Installation",
    		relatedTopics: ["api-keys", "quickstart"],
    	},
    	"create-payees": {
    		title: "Create Payees",
    		relatedTopics: ["create-payee", "search-payees"],
    	},
    	"send-payments": {
    		title: "Send Payments",
    		relatedTopics: ["check-balances", "create-payees"],
    	},
    	"create-payee": {
    		title: "Create Payee",
    		relatedTopics: ["create-payees", "search-payees"],
    	},
    	"search-payees": {
    		title: "Search Payees",
    		relatedTopics: ["create-payee", "create-payees"],
    	},
    	"check-balances": {
    		title: "Check Balances",
    		relatedTopics: ["send-payments"],
    	},
    	"bill-payment-agent": {
    		title: "Bill Payment Agent",
    		relatedTopics: ["send-payments"],
    	},
    	"api-reference": {
    		title: "API Reference",
    		relatedTopics: ["error-handling", "api-keys"],
    	},
    	"api-keys": {
    		title: "API Keys",
    		relatedTopics: ["api-reference", "setup-and-installation"],
    	},
    	"error-handling": {
    		title: "Error Handling",
    		relatedTopics: ["api-reference"],
    	},
    };

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It only states the action ('Search') without detailing traits such as search scope, result format, pagination, rate limits, or authentication needs. This is inadequate for a tool with zero annotation coverage.

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 front-loaded and appropriately sized for the tool's simple purpose, earning the highest score for conciseness.

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

Completeness2/5

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

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what the search returns, how results are structured, or any behavioral context. For a search tool with no structured support, this leaves significant gaps in understanding.

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?

The schema description coverage is 100%, with the 'query' parameter documented as 'Search term'. The description adds no additional meaning beyond this, such as query syntax or examples. Given the high schema coverage, the baseline score of 3 is appropriate.

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 verb ('Search') and resource ('PaymanAI documentation'), making the purpose evident. However, it doesn't differentiate from sibling tools like 'get-documentation' or 'solve-problem', which might have overlapping functionality, so it doesn't achieve the highest score.

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?

The description provides no guidance on when to use this tool versus alternatives like 'get-documentation' or 'solve-problem'. It lacks explicit instructions on context or exclusions, leaving the agent to infer usage from the tool name alone.

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