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"],
    	},
    };
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. The description only states what the tool does ('Search through PaymanAI documentation') without adding any behavioral context such as how results are returned (e.g., relevance ranking, pagination), what happens with no matches, or any limitations (e.g., search scope, rate limits). It lacks details beyond the basic action.

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: 'Search through PaymanAI documentation'. It's front-loaded with the core action and resource, with zero wasted words. This is appropriately sized for a simple tool, making it easy to understand at a glance.

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 tool returns (e.g., search results format, error handling) or provide behavioral context. For a search tool with no structured output information, the description should compensate by detailing expected outcomes, but it only states the basic action without addressing these gaps.

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 input schema has 100% description coverage, with the single parameter 'query' documented as 'Search term'. The description doesn't add any meaning beyond this, such as examples of effective queries or search syntax. Since schema coverage is high (>80%), the baseline score of 3 is appropriate, as the schema already provides adequate parameter information.

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 tool's purpose as 'Search through PaymanAI documentation', which includes a specific verb ('Search') and resource ('PaymanAI documentation'). However, it doesn't distinguish this tool from its sibling tools like 'get-documentation' or 'solve-problem', which might have overlapping functionality. The purpose is clear but lacks sibling differentiation.

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. With sibling tools like 'get-documentation' (which might retrieve specific documentation) and 'solve-problem' (which might handle troubleshooting), there's no indication of when this search function is preferred. The description offers no context, exclusions, or alternatives.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Vanshika-Rana/payman-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server