octocode-mcp
Version:
Model Context Protocol (MCP) server for advanced GitHub repository analysis and code discovery. Provides AI assistants with powerful tools to search, analyze, and understand codebases across GitHub.
73 lines (72 loc) • 2.57 kB
TypeScript
import { CallToolResult } from '@modelcontextprotocol/sdk/types';
/**
* Standardized response format for all tool responses
*/
export interface ToolResponse {
/** Primary data payload (GitHub API responses, packages, file contents, etc.) */
data: unknown;
/** Helpful hints for AI assistants (recovery tips, usage guidance) */
hints: string[];
}
/**
* Simplified result creation with standardized format
*/
export declare function createResult(options: {
data: unknown;
hints?: string[];
isError?: boolean;
}): CallToolResult;
/**
* Creates the final response format for tool responses with security processing.
*
* This function performs comprehensive processing on structured tool responses:
* 1. Recursively cleans the data by removing empty objects, null, undefined, and NaN values
* 2. Optionally converts to YAML format if beta features are enabled
* 3. Serializes structured data to JSON string format
* 4. Sanitizes content to remove malicious patterns and prompt injections
* 5. Masks sensitive information (API keys, tokens, credentials)
*
* @param responseData - The structured tool response data
* @param keysPriority - Optional array of keys to prioritize in YAML output ordering
* @returns Sanitized and formatted string ready for safe transmission
*
* @example
* ```typescript
* const responseData: ToolResponse = {
* data: { repos: [...] },
* hints: ["Try narrowing your search"]
* };
* const formatted = createResponseFormat(responseData, ['queryId', 'reasoning']);
* ```
*
* @security
* - Removes potential prompt injection attacks
* - Masks sensitive credentials and tokens
* - Handles unserializable data gracefully
* - Preserves structured data format for AI parsing
*/
export declare function createResponseFormat(responseData: ToolResponse, keysPriority?: string[]): string;
/**
* Convert ISO timestamp to DDMMYYYY format
*/
export declare function toDDMMYYYY(timestamp: string): string;
/**
* Convert repository URL to owner/repo format
*/
export declare function simplifyRepoUrl(url: string): string;
/**
* Extract first line of commit message
*/
export declare function getCommitTitle(message: string): string;
/**
* Convert bytes to human readable format
*/
export declare function humanizeBytes(bytes: number): string;
/**
* Simplify GitHub URL to relative path
*/
export declare function simplifyGitHubUrl(url: string): string;
/**
* Clean and optimize text match context
*/
export declare function optimizeTextMatch(fragment: string, maxLength?: number): string;