|
| 1 | +package mcpserver |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/google/jsonschema-go/jsonschema" |
| 5 | + "github.com/modelcontextprotocol/go-sdk/mcp" |
| 6 | +) |
| 7 | + |
| 8 | +// Canonical MCP tool names group operations by capability and side-effect boundary. |
| 9 | +const ( |
| 10 | + ToolSearchRepositories = "gitcontribute.corpus.search_repositories" |
| 11 | + ToolSearchThreads = "gitcontribute.corpus.search_threads" |
| 12 | + ToolSearchCode = "gitcontribute.corpus.search_code" |
| 13 | + ToolGetRepository = "gitcontribute.corpus.get_repository" |
| 14 | + ToolGetThread = "gitcontribute.corpus.get_thread" |
| 15 | + ToolGetRepositoryDossier = "gitcontribute.corpus.get_repository_dossier" |
| 16 | + ToolExplainMatch = "gitcontribute.corpus.explain_match" |
| 17 | + ToolGetInvestigation = "gitcontribute.corpus.get_investigation" |
| 18 | + ToolListOpportunities = "gitcontribute.corpus.list_opportunities" |
| 19 | + ToolGetOpportunity = "gitcontribute.corpus.get_opportunity" |
| 20 | + ToolGetEvidence = "gitcontribute.corpus.get_evidence" |
| 21 | + ToolGetReadiness = "gitcontribute.corpus.get_readiness" |
| 22 | + ToolFindClusters = "gitcontribute.corpus.find_clusters" |
| 23 | + ToolFindNeighbors = "gitcontribute.corpus.find_neighbors" |
| 24 | + ToolGetCoverage = "gitcontribute.corpus.get_coverage" |
| 25 | + ToolGetLens = "gitcontribute.corpus.get_lens" |
| 26 | + ToolBuildRepositoryDossier = "gitcontribute.corpus.build_repository_dossier" |
| 27 | + ToolGetJob = "gitcontribute.jobs.get" |
| 28 | + ToolCancelJob = "gitcontribute.jobs.cancel" |
| 29 | + ToolStartCrawl = "gitcontribute.github.start_crawl" |
| 30 | + ToolSyncRepository = "gitcontribute.github.sync_repository" |
| 31 | + ToolHydrateThread = "gitcontribute.github.hydrate_thread" |
| 32 | + ToolHydrateRepository = "gitcontribute.github.hydrate_repository" |
| 33 | + ToolCreateWorkspace = "gitcontribute.workspace.create" |
| 34 | + ToolDefineValidation = "gitcontribute.validation.define" |
| 35 | + ToolRunValidation = "gitcontribute.validation.run" |
| 36 | + ToolStartInvestigation = "gitcontribute.workflow.start_investigation" |
| 37 | + ToolRecordHypothesis = "gitcontribute.workflow.record_hypothesis" |
| 38 | + ToolCheckDuplicates = "gitcontribute.workflow.check_duplicates" |
| 39 | + ToolCheckCollisions = "gitcontribute.workflow.check_collisions" |
| 40 | + ToolPromoteOpportunity = "gitcontribute.workflow.promote_opportunity" |
| 41 | + ToolPrepareContribution = "gitcontribute.workflow.prepare_contribution" |
| 42 | +) |
| 43 | + |
| 44 | +var canonicalToolNames = []string{ |
| 45 | + ToolSearchRepositories, |
| 46 | + ToolSearchThreads, |
| 47 | + ToolSearchCode, |
| 48 | + ToolGetRepository, |
| 49 | + ToolGetThread, |
| 50 | + ToolGetRepositoryDossier, |
| 51 | + ToolExplainMatch, |
| 52 | + ToolGetInvestigation, |
| 53 | + ToolListOpportunities, |
| 54 | + ToolGetOpportunity, |
| 55 | + ToolGetEvidence, |
| 56 | + ToolGetReadiness, |
| 57 | + ToolFindClusters, |
| 58 | + ToolFindNeighbors, |
| 59 | + ToolGetCoverage, |
| 60 | + ToolGetLens, |
| 61 | + ToolBuildRepositoryDossier, |
| 62 | + ToolGetJob, |
| 63 | + ToolCancelJob, |
| 64 | + ToolStartCrawl, |
| 65 | + ToolSyncRepository, |
| 66 | + ToolHydrateThread, |
| 67 | + ToolHydrateRepository, |
| 68 | + ToolCreateWorkspace, |
| 69 | + ToolDefineValidation, |
| 70 | + ToolRunValidation, |
| 71 | + ToolStartInvestigation, |
| 72 | + ToolRecordHypothesis, |
| 73 | + ToolCheckDuplicates, |
| 74 | + ToolCheckCollisions, |
| 75 | + ToolPromoteOpportunity, |
| 76 | + ToolPrepareContribution, |
| 77 | +} |
| 78 | + |
| 79 | +type catalogTool[In, Out any] struct { |
| 80 | + name, title, description string |
| 81 | + annotations *mcp.ToolAnnotations |
| 82 | + input *jsonschema.Schema |
| 83 | + output *jsonschema.Schema |
| 84 | + handler mcp.ToolHandlerFor[In, Out] |
| 85 | +} |
| 86 | + |
| 87 | +func addCatalogTool[In, Out any](server *mcp.Server, tool catalogTool[In, Out]) { |
| 88 | + mcp.AddTool(server, &mcp.Tool{ |
| 89 | + Name: tool.name, |
| 90 | + Title: tool.title, |
| 91 | + Description: tool.description, |
| 92 | + Annotations: tool.annotations, |
| 93 | + InputSchema: tool.input, |
| 94 | + OutputSchema: tool.output, |
| 95 | + }, tool.handler) |
| 96 | +} |
| 97 | + |
| 98 | +func readOnlyAnnotations() *mcp.ToolAnnotations { |
| 99 | + return &mcp.ToolAnnotations{ |
| 100 | + ReadOnlyHint: true, |
| 101 | + IdempotentHint: true, |
| 102 | + OpenWorldHint: boolPtr(false), |
| 103 | + DestructiveHint: boolPtr(false), |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +func localWriteAnnotations(idempotent bool) *mcp.ToolAnnotations { |
| 108 | + return &mcp.ToolAnnotations{ |
| 109 | + ReadOnlyHint: false, |
| 110 | + IdempotentHint: idempotent, |
| 111 | + OpenWorldHint: boolPtr(false), |
| 112 | + DestructiveHint: boolPtr(false), |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +func networkReadAnnotations() *mcp.ToolAnnotations { |
| 117 | + return &mcp.ToolAnnotations{ |
| 118 | + ReadOnlyHint: false, |
| 119 | + IdempotentHint: false, |
| 120 | + OpenWorldHint: boolPtr(true), |
| 121 | + DestructiveHint: boolPtr(false), |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +func executionAnnotations() *mcp.ToolAnnotations { |
| 126 | + return &mcp.ToolAnnotations{ |
| 127 | + ReadOnlyHint: false, |
| 128 | + IdempotentHint: false, |
| 129 | + OpenWorldHint: boolPtr(false), |
| 130 | + DestructiveHint: boolPtr(true), |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +func cancellationAnnotations() *mcp.ToolAnnotations { |
| 135 | + return &mcp.ToolAnnotations{ |
| 136 | + ReadOnlyHint: false, |
| 137 | + IdempotentHint: true, |
| 138 | + OpenWorldHint: boolPtr(false), |
| 139 | + DestructiveHint: boolPtr(true), |
| 140 | + } |
| 141 | +} |
| 142 | + |
| 143 | +func noSchemaCustomization(*jsonschema.Schema) {} |
0 commit comments