#!/usr/bin/env node
/**
* PT-MCP Server (Paul Test Man Context Protocol)
*
* "Where am I now?"
*
* Named after Paul Marcarelli, the Verizon "Test Man" who famously asked
* "Can you hear me now?" across America. PT-MCP asks "Where am I now?"
* to provide comprehensive context understanding through integrated
* knowledge graphs (YAGO 4.5) and semantic schemas (Schema.org).
*
* Provides codebase analysis and context generation with semantic meaning
* for AI coding assistants through the Model Context Protocol.
*/
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { ListResourcesRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
import { registerTools } from "./tools/index.js";
import { registerResources } from "./resources/index.js";
const SERVER_NAME = "pt-mcp";
const SERVER_VERSION = "0.1.0";
/**
* Main server initialization
*/
async function main() {
const server = new Server({
name: SERVER_NAME,
version: SERVER_VERSION,
}, {
capabilities: {
tools: {},
resources: {},
},
});
// Register tool handlers
registerTools(server);
// Register resource handlers
registerResources(server);
// List tools handler
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: "analyze_codebase",
description: "Perform comprehensive codebase analysis including structure, dependencies, and metrics",
inputSchema: {
type: "object",
properties: {
path: {
type: "string",
description: "Root directory path to analyze",
},
languages: {
type: "array",
items: { type: "string" },
description: "Languages to analyze (auto-detect if omitted)",
},
depth: {
type: "number",
description: "Analysis depth (1-5, default: 3)",
minimum: 1,
maximum: 5,
default: 3,
},
include_patterns: {
type: "array",
items: { type: "string" },
description: "Glob patterns to include",
},
exclude_patterns: {
type: "array",
items: { type: "string" },
description: "Glob patterns to exclude",
},
analysis_type: {
type: "string",
enum: ["quick", "standard", "deep"],
description: "Analysis thoroughness level",
default: "standard",
},
},
required: ["path"],
},
},
{
name: "generate_context",
description: "Generate context files in specified format for the codebase",
inputSchema: {
type: "object",
properties: {
path: {
type: "string",
description: "Root directory path",
},
format: {
type: "string",
enum: ["cursorrules", "cursor_dir", "spec_md", "agents_md", "custom"],
description: "Context file format to generate",
},
output_path: {
type: "string",
description: "Output path for generated files (optional)",
},
analysis_result: {
type: "object",
description: "Previous analysis result to use (optional)",
},
options: {
type: "object",
description: "Format-specific options",
},
},
required: ["path", "format"],
},
},
{
name: "update_context",
description: "Incrementally update existing context files based on code changes",
inputSchema: {
type: "object",
properties: {
path: {
type: "string",
description: "Root directory path",
},
changed_files: {
type: "array",
items: { type: "string" },
description: "List of changed file paths",
},
context_format: {
type: "string",
enum: ["cursorrules", "cursor_dir", "spec_md", "agents_md"],
description: "Context format to update",
},
force_full_regeneration: {
type: "boolean",
description: "Force complete regeneration instead of incremental update",
default: false,
},
},
required: ["path", "changed_files", "context_format"],
},
},
{
name: "extract_patterns",
description: "Identify and extract architectural and coding patterns from the codebase",
inputSchema: {
type: "object",
properties: {
path: {
type: "string",
description: "Root directory path",
},
pattern_types: {
type: "array",
items: { type: "string" },
description: "Types of patterns to extract (architectural, design, naming, testing)",
},
min_occurrences: {
type: "number",
description: "Minimum occurrences to consider a pattern",
default: 3,
},
},
required: ["path"],
},
},
{
name: "analyze_dependencies",
description: "Analyze and map internal and external dependencies",
inputSchema: {
type: "object",
properties: {
path: {
type: "string",
description: "Root directory path",
},
include_external: {
type: "boolean",
description: "Include external package dependencies",
default: true,
},
include_internal: {
type: "boolean",
description: "Include internal module dependencies",
default: true,
},
max_depth: {
type: "number",
description: "Maximum dependency depth to traverse",
default: 5,
},
},
required: ["path"],
},
},
{
name: "watch_project",
description: "Start monitoring project for changes and auto-update context",
inputSchema: {
type: "object",
properties: {
path: {
type: "string",
description: "Root directory path to watch",
},
context_formats: {
type: "array",
items: { type: "string" },
description: "Context formats to auto-update",
},
debounce_ms: {
type: "number",
description: "Debounce delay in milliseconds",
default: 1000,
},
watch_patterns: {
type: "array",
items: { type: "string" },
description: "Glob patterns to watch",
},
},
required: ["path", "context_formats"],
},
},
{
name: "extract_api_surface",
description: "Extract and document public API surface of the codebase",
inputSchema: {
type: "object",
properties: {
path: {
type: "string",
description: "Root directory path",
},
include_private: {
type: "boolean",
description: "Include private/internal APIs",
default: false,
},
output_format: {
type: "string",
enum: ["markdown", "json", "typescript"],
description: "Output format for API documentation",
default: "markdown",
},
},
required: ["path"],
},
},
{
name: "validate_context",
description: "Validate accuracy and completeness of generated context files",
inputSchema: {
type: "object",
properties: {
path: {
type: "string",
description: "Root directory path",
},
context_path: {
type: "string",
description: "Path to context files to validate",
},
checks: {
type: "array",
items: { type: "string" },
description: "Validation checks to perform",
},
},
required: ["path", "context_path"],
},
},
],
};
});
// List resources handler
server.setRequestHandler(ListResourcesRequestSchema, async () => {
return {
resources: [
{
uri: "context://project/{path}",
name: "Project Context",
description: "Current project context including structure, patterns, and dependencies",
mimeType: "application/json",
},
{
uri: "context://patterns/{path}",
name: "Detected Patterns",
description: "Architectural and coding patterns detected in the codebase",
mimeType: "application/json",
},
{
uri: "context://dependencies/{path}",
name: "Dependency Graph",
description: "Internal and external dependency relationships",
mimeType: "application/json",
},
],
};
});
// Start server with stdio transport
const transport = new StdioServerTransport();
await server.connect(transport);
console.error(`${SERVER_NAME} v${SERVER_VERSION} started`);
}
// Run server
main().catch((error) => {
console.error("Fatal error:", error);
process.exit(1);
});
//# sourceMappingURL=index.js.map