@githits/mcp 0.11.0 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,6 +4,13 @@ Reusable MCP server APIs and tool registrations for GitHits.
4
4
 
5
5
  This package exposes transport-neutral helpers for servers that want the GitHits MCP tool surface without the local `githits` CLI startup, auth storage, or Commander wiring.
6
6
 
7
+ > **Browser boundary:** only the selected `@githits/mcp/tools` resolved runtime
8
+ > graph is browser-safe. Installing `@githits/mcp` still installs its MCP SDK
9
+ > and other Node-oriented dependencies; the package root and
10
+ > `@githits/mcp/client` remain Node entries. The `/tools` entry does not provide
11
+ > filesystem access, authentication implementation or storage, configuration
12
+ > discovery, or any other host behavior.
13
+
7
14
  ## API
8
15
 
9
16
  - `createMcpServer(options)` creates an MCP server with GitHits tools registered.
@@ -11,11 +18,83 @@ This package exposes transport-neutral helpers for servers that want the GitHits
11
18
  - `getMcpToolDescriptors()` returns static tool metadata without requiring concrete services.
12
19
  - `buildMcpQuickStart(options?)` builds the guide returned by the read-only `quick_start` tool.
13
20
  - `buildMcpInstructions(options?)` is a deprecated compatibility alias for `buildMcpQuickStart()`.
14
- - `@githits/mcp/client` exports concrete GitHits service implementations, static token providers, URL/config helpers, request-header helpers, telemetry helpers, and registry helpers for remote MCP servers.
21
+ - `@githits/mcp/client` exports concrete GitHits service implementations, static token providers, URL/config helpers, request-header helpers, the `ServiceDiagnostics` type, and registry helpers for remote MCP servers. Service clients are silent by default; hosts that need operation spans or debug events inject a `ServiceDiagnostics` implementation through their runtime options. Hosts must explicitly opt into sensitive diagnostic areas and own the resulting privacy and retention policy.
22
+ - The former module-global telemetry lifecycle helpers (`startTelemetrySpan`, `endTelemetrySpan`, `flushTelemetry`, and `withTelemetrySpan`) are not exported from `@githits/mcp/client`. Remote hosts own diagnostics lifecycle and destinations through injection.
15
23
  - `@githits/mcp/smoke-test` exports reusable smoke assertions and `runMcpSmoke()` for remote MCP server validation.
24
+ - `@githits/mcp/tools` exports the browser-callable `get_example` factory and
25
+ its structural service contract, plus `toCallableTool()` and the stable
26
+ callable result/schema types. It also exports the neutral
27
+ `AuthenticationError`, `ApiRateLimitError`, `FetchTimeoutError`, and
28
+ `TermsAcceptanceRequiredError` constructors used by the callable error
29
+ boundary.
30
+
31
+ ## Browser-callable `@githits/mcp/tools`
32
+
33
+ The `/tools` entry is a small frontend-facing surface. Inject a service with
34
+ only the `search(params, options?)` method, create the existing `get_example`
35
+ definition, and adapt it to a plain callable object:
36
+
37
+ ```ts
38
+ import {
39
+ createGetExampleTool,
40
+ toCallableTool,
41
+ type GetExampleRequestOptions,
42
+ type GetExampleSearchParams,
43
+ type GetExampleService,
44
+ } from "@githits/mcp/tools";
45
+
46
+ // Supplied by the application; it owns transport, authentication, and CORS.
47
+ declare function searchExamples(
48
+ params: GetExampleSearchParams,
49
+ options?: GetExampleRequestOptions,
50
+ ): Promise<string>;
51
+
52
+ const service: GetExampleService = {
53
+ search: (params, options) => searchExamples(params, options),
54
+ };
55
+
56
+ const tool = toCallableTool(createGetExampleTool(service));
57
+ ```
58
+
59
+ `toCallableTool()` wraps the tool's Zod object schema, emits input-mode JSON
60
+ Schema, and validates/defaults input before calling the service. The omitted
61
+ `format` field remains optional in the schema and defaults to `"text-v1"`.
62
+ Unknown object properties follow the normal Zod object behavior. Successful
63
+ and structured error results are returned as the serializable `ToolResult`
64
+ shape. If the caller supplies an `AbortSignal`, it is forwarded unchanged to
65
+ the service; caller cancellation rejects the execution rather than becoming an
66
+ error result.
67
+
68
+ An injected browser service should throw one of the exported neutral error
69
+ constructors when it wants `get_example` to return a structured
70
+ `AUTH_REQUIRED`, `RATE_LIMITED`, `TIMEOUT`, or `TERMS_ACCEPTANCE_REQUIRED`
71
+ `ToolResult`. This is an explicit thrown-error contract, not automatic HTTP
72
+ response classification. Callable authentication remediation is host-neutral:
73
+ `Authenticate with GitHits, then retry.` Terms errors use the canonical
74
+ `acceptanceUrl` action. Other errors remain `UNKNOWN`.
75
+
76
+ A frontend can add a small registration adapter for its WebMCP host API. The
77
+ adapter owns the host-specific registration call and passes its signal through;
78
+ the callable surface is not a generic protocol-conversion layer:
79
+
80
+ ```ts
81
+ document.modelContext.registerTool({
82
+ name: tool.name,
83
+ description: tool.description,
84
+ inputSchema: tool.inputSchema,
85
+ annotations: tool.annotations,
86
+ execute: (input, options) =>
87
+ tool.execute(input, { signal: options?.signal }),
88
+ });
89
+ ```
90
+
91
+ The frontend owns `document.modelContext`, authentication and login UI, its
92
+ response-to-error conversion, request transport, CORS policy, and any
93
+ user-facing recovery. The injected service decides how the app-owned backend
94
+ boundary is authenticated and reached.
16
95
 
17
96
  The package expects callers to provide service implementations through `McpToolServices` or a request-scoped `McpToolServicesProvider`. GitHits does not populate MCP initialize instructions because hosts expose them inconsistently; `quick_start` owns shared guidance instead. Callers may still pass their own `instructions` explicitly. Use `quickStartOptions` to configure the guide. Servers can pass `traceTool` to `createMcpServer()` or `registerMcpTools()` to wrap public tool execution for instrumentation without receiving arguments or auth data.
18
97
 
19
- Only imports from `@githits/mcp`, `@githits/mcp/client`, `@githits/mcp/smoke-test`, and `@githits/mcp/package.json` are public. The workspace alias `@githits/mcp/internal` is not exported, is not supported for external consumers, and must not be used by remote MCP server implementations.
98
+ Only imports from `@githits/mcp`, `@githits/mcp/client`, `@githits/mcp/smoke-test`, `@githits/mcp/tools`, and `@githits/mcp/package.json` are public. The workspace alias `@githits/mcp/internal` is not exported, is not supported for external consumers, and must not be used by remote MCP server implementations.
20
99
 
21
100
  Remote MCP servers should provide request-scoped services through `createMcpServer()` and keep transport, auth/session handling, deployment config, and observability outside this package.
package/dist/client.d.ts CHANGED
@@ -61,6 +61,28 @@ interface CreateClientHeaderBuilderOptions {
61
61
  * relying on module-level CLI state.
62
62
  */
63
63
  declare function createClientHeaderBuilder(options: CreateClientHeaderBuilderOptions): ClientHeaderBuilder;
64
+ /**
65
+ * Host-supplied diagnostics for transport-neutral service clients.
66
+ *
67
+ * Implementations may record operation timings or debug events in whatever
68
+ * way is appropriate for their host. Core does not provide a default and
69
+ * remains silent when diagnostics are omitted. Core callers gate every debug
70
+ * event through `isEnabled(area)`; when it returns `false`, the corresponding
71
+ * debug call is suppressed entirely. Returning `true` is therefore both a log
72
+ * filter and a content-disclosure decision for the host.
73
+ *
74
+ * In particular, the `code-nav-wire` area may carry the exact GraphQL document
75
+ * and request variables, including caller query text, so it requires separate
76
+ * explicit opt-in. The `code-nav` and `pkg-graphql` schema-mismatch paths may
77
+ * carry raw backend error text, and an enabled area may select that raw error
78
+ * content instead of the sanitized message. These areas are not PII-safe;
79
+ * hosts own their privacy and retention policy for any enabled diagnostics.
80
+ */
81
+ interface ServiceDiagnostics {
82
+ withOperation<T>(name: string, operation: () => Promise<T>): Promise<T>;
83
+ isEnabled(area: string): boolean;
84
+ debug(area: string, event: Record<string, unknown>): void;
85
+ }
64
86
  interface TokenProvider {
65
87
  /** Get a valid token, refreshing proactively or reactively as needed. */
66
88
  getToken(): Promise<string | undefined>;
@@ -637,6 +659,7 @@ declare class CodeNavigationServiceImpl implements CodeNavigationService, CodeDi
637
659
  clientHeaders?: ClientHeaderBuilder;
638
660
  userAgent?: string;
639
661
  clientVersion?: string;
662
+ diagnostics?: ServiceDiagnostics;
640
663
  });
641
664
  private postGraphqlWithTargetResolutionFallback;
642
665
  search(params: UnifiedSearchParams): Promise<UnifiedSearchOutcome>;
@@ -717,6 +740,10 @@ interface SearchParams {
717
740
  licenseMode?: "strict" | "yolo" | "custom";
718
741
  includeExplanation?: boolean;
719
742
  }
743
+ /** Optional browser-standard controls for a GitHits service request. */
744
+ interface GitHitsServiceRequestOptions {
745
+ signal?: AbortSignal;
746
+ }
720
747
  /**
721
748
  * Parameters for feedback API call.
722
749
  *
@@ -743,13 +770,14 @@ interface GitHitsServiceRuntimeOptions {
743
770
  clientHeaders?: ClientHeaderBuilder;
744
771
  userAgent?: string;
745
772
  exampleRequestTimeoutMs?: number;
773
+ diagnostics?: ServiceDiagnostics;
746
774
  }
747
775
  /**
748
776
  * Service interface for GitHits REST API.
749
777
  */
750
778
  interface GitHitsService {
751
779
  /** Search for code examples. Returns markdown-formatted result. */
752
- search(params: SearchParams): Promise<string>;
780
+ search(params: SearchParams, options?: GitHitsServiceRequestOptions): Promise<string>;
753
781
  /** Get all supported languages. */
754
782
  getLanguages(): Promise<Language[]>;
755
783
  /** Search supported languages using backend-ranked matching. */
@@ -767,7 +795,7 @@ declare class GitHitsServiceImpl implements GitHitsService {
767
795
  private readonly fetchTimeoutMs;
768
796
  private readonly runtime;
769
797
  constructor(apiUrl: string, token: string, fetchFn?: typeof fetch | undefined, fetchTimeoutMs?: number | undefined, runtime?: GitHitsServiceRuntimeOptions);
770
- search(params: SearchParams): Promise<string>;
798
+ search(params: SearchParams, options?: GitHitsServiceRequestOptions): Promise<string>;
771
799
  getLanguages(): Promise<Language[]>;
772
800
  searchLanguages(query: string, limit?: number): Promise<Language[]>;
773
801
  submitFeedback(params: FeedbackParams): Promise<FeedbackResult>;
@@ -1410,6 +1438,7 @@ declare class PackageIntelligenceServiceImpl implements PackageIntelligenceServi
1410
1438
  clientHeaders?: ClientHeaderBuilder;
1411
1439
  userAgent?: string;
1412
1440
  clientVersion?: string;
1441
+ diagnostics?: ServiceDiagnostics;
1413
1442
  });
1414
1443
  packageSummary(params: PackageSummaryParams): Promise<PackageSummary>;
1415
1444
  private executePackageSummary;
@@ -1456,7 +1485,7 @@ declare class RefreshingGitHitsService implements GitHitsService {
1456
1485
  private readonly serviceFactory;
1457
1486
  private readonly runtime;
1458
1487
  constructor(apiUrl: string, tokenProvider: TokenProvider, serviceFactory?: ServiceFactory | undefined, runtime?: GitHitsServiceRuntimeOptions);
1459
- search(params: SearchParams): Promise<string>;
1488
+ search(params: SearchParams, options?: GitHitsServiceRequestOptions): Promise<string>;
1460
1489
  getLanguages(): Promise<Language[]>;
1461
1490
  searchLanguages(query: string, limit?: number): Promise<Language[]>;
1462
1491
  submitFeedback(params: FeedbackParams): Promise<FeedbackResult>;
@@ -1466,15 +1495,4 @@ declare class RefreshingGitHitsService implements GitHitsService {
1466
1495
  */
1467
1496
  private withTokenRefresh;
1468
1497
  }
1469
- type TelemetryAttributeValue = string | number | boolean;
1470
- interface TelemetryAttributes {
1471
- [key: string]: TelemetryAttributeValue | undefined;
1472
- }
1473
- interface TelemetrySpanHandle {
1474
- id: number;
1475
- }
1476
- declare function withTelemetrySpan<T>(name: string, operation: () => Promise<T>, attributes?: TelemetryAttributes): Promise<T>;
1477
- declare function startTelemetrySpan(name: string, attributes?: TelemetryAttributes): TelemetrySpanHandle | undefined;
1478
- declare function endTelemetrySpan(handle: TelemetrySpanHandle | undefined, attributes?: TelemetryAttributes): void;
1479
- declare function flushTelemetry(exitCode?: number): void;
1480
- export { AgentInfo, CodeDiffError, CodeDiffErrorDetails, CodeDiffErrorRef, CodeDiffMode, CodeDiffOptions, CodeDiffPackageInfo, CodeDiffPackageTarget, CodeDiffParams, CodeDiffPartialResult, CodeDiffRefKind, CodeDiffRefResolution, CodeDiffRepositoryTarget, CodeDiffResult, CodeDiffService, CodeDiffTarget, CodeDiffVersionSource, CodeNavigationService, CodeNavigationServiceImpl, ContentModification, ContentSafety, DEFAULT_API_URL, DEFAULT_CODE_NAV_URL, DEFAULT_MCP_URL, GitHitsService, GitHitsServiceImpl, PKGSEER_REGISTRY_LIST, PackageIntelligenceService, PackageIntelligenceServiceImpl, RawCodeDiff, RawCodeDiffContentCoverage, RawCodeDiffContentFailure, RawCodeDiffFile, RawCodeDiffFileContentStatus, RawCodeDiffFileStatus, RawCodeDiffPathEncoding, RawCodeDiffScope, RawCodeDiffScopeStatus, RawCodeDiffSummary, RefreshingGitHitsService, TokenProvider, createClientHeaderBuilder, createStaticTokenProvider, endTelemetrySpan, flushTelemetry, getApiUrl, getCodeNavigationUrl, getEnvApiToken, getMcpUrl, startTelemetrySpan, toPkgseerRegistry, toPkgseerRegistryLowercase, withTelemetrySpan };
1498
+ export { AgentInfo, CodeDiffError, CodeDiffErrorDetails, CodeDiffErrorRef, CodeDiffMode, CodeDiffOptions, CodeDiffPackageInfo, CodeDiffPackageTarget, CodeDiffParams, CodeDiffPartialResult, CodeDiffRefKind, CodeDiffRefResolution, CodeDiffRepositoryTarget, CodeDiffResult, CodeDiffService, CodeDiffTarget, CodeDiffVersionSource, CodeNavigationService, CodeNavigationServiceImpl, ContentModification, ContentSafety, DEFAULT_API_URL, DEFAULT_CODE_NAV_URL, DEFAULT_MCP_URL, GitHitsService, GitHitsServiceImpl, PKGSEER_REGISTRY_LIST, PackageIntelligenceService, PackageIntelligenceServiceImpl, RawCodeDiff, RawCodeDiffContentCoverage, RawCodeDiffContentFailure, RawCodeDiffFile, RawCodeDiffFileContentStatus, RawCodeDiffFileStatus, RawCodeDiffPathEncoding, RawCodeDiffScope, RawCodeDiffScopeStatus, RawCodeDiffSummary, RefreshingGitHitsService, ServiceDiagnostics, TokenProvider, createClientHeaderBuilder, createStaticTokenProvider, getApiUrl, getCodeNavigationUrl, getEnvApiToken, getMcpUrl, toPkgseerRegistry, toPkgseerRegistryLowercase };
package/dist/client.js CHANGED
@@ -1 +1 @@
1
- import{CodeDiffError,CodeNavigationServiceImpl,DEFAULT_API_URL,DEFAULT_CODE_NAV_URL,DEFAULT_MCP_URL,GitHitsServiceImpl,PKGSEER_REGISTRY_LIST,PackageIntelligenceServiceImpl,RefreshingGitHitsService,createClientHeaderBuilder,createStaticTokenProvider,endTelemetrySpan,flushTelemetry,getApiUrl,getCodeNavigationUrl,getEnvApiToken,getMcpUrl,startTelemetrySpan,toPkgseerRegistry,toPkgseerRegistryLowercase,withTelemetrySpan}from"./shared/chunk-7xsjs2xx.js";export{CodeDiffError,CodeNavigationServiceImpl,DEFAULT_API_URL,DEFAULT_CODE_NAV_URL,DEFAULT_MCP_URL,GitHitsServiceImpl,PKGSEER_REGISTRY_LIST,PackageIntelligenceServiceImpl,RefreshingGitHitsService,createClientHeaderBuilder,createStaticTokenProvider,endTelemetrySpan,flushTelemetry,getApiUrl,getCodeNavigationUrl,getEnvApiToken,getMcpUrl,startTelemetrySpan,toPkgseerRegistry,toPkgseerRegistryLowercase,withTelemetrySpan};
1
+ import{CodeDiffError,CodeNavigationServiceImpl,DEFAULT_API_URL,DEFAULT_CODE_NAV_URL,DEFAULT_MCP_URL,GitHitsServiceImpl,PKGSEER_REGISTRY_LIST,PackageIntelligenceServiceImpl,RefreshingGitHitsService,createClientHeaderBuilder,createStaticTokenProvider,getApiUrl,getCodeNavigationUrl,getEnvApiToken,getMcpUrl,toPkgseerRegistry,toPkgseerRegistryLowercase}from"./shared/chunk-mjxp4hpz.js";import"./shared/chunk-51x6tx02.js";export{CodeDiffError,CodeNavigationServiceImpl,DEFAULT_API_URL,DEFAULT_CODE_NAV_URL,DEFAULT_MCP_URL,GitHitsServiceImpl,PKGSEER_REGISTRY_LIST,PackageIntelligenceServiceImpl,RefreshingGitHitsService,createClientHeaderBuilder,createStaticTokenProvider,getApiUrl,getCodeNavigationUrl,getEnvApiToken,getMcpUrl,toPkgseerRegistry,toPkgseerRegistryLowercase};
package/dist/index.d.ts CHANGED
@@ -451,6 +451,10 @@ interface SearchParams {
451
451
  licenseMode?: "strict" | "yolo" | "custom";
452
452
  includeExplanation?: boolean;
453
453
  }
454
+ /** Optional browser-standard controls for a GitHits service request. */
455
+ interface GitHitsServiceRequestOptions {
456
+ signal?: AbortSignal;
457
+ }
454
458
  /**
455
459
  * Parameters for feedback API call.
456
460
  *
@@ -478,7 +482,7 @@ interface FeedbackResult {
478
482
  */
479
483
  interface GitHitsService {
480
484
  /** Search for code examples. Returns markdown-formatted result. */
481
- search(params: SearchParams): Promise<string>;
485
+ search(params: SearchParams, options?: GitHitsServiceRequestOptions): Promise<string>;
482
486
  /** Get all supported languages. */
483
487
  getLanguages(): Promise<Language[]>;
484
488
  /** Search supported languages using backend-ranked matching. */
@@ -1110,14 +1114,31 @@ interface PackageIntelligenceService {
1110
1114
  listPackageDocs(params: ListPackageDocsParams): Promise<PackageDocsList>;
1111
1115
  readPackageDoc(params: ReadPackageDocParams): Promise<PackageDocResult>;
1112
1116
  }
1113
- import { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
1114
1117
  import { z } from "zod";
1115
1118
  /** Annotation fields required by OpenAI's MCP marketplace validation. */
1116
- interface CompleteToolAnnotations extends ToolAnnotations {
1119
+ interface CompleteToolAnnotations {
1120
+ title?: string;
1117
1121
  readOnlyHint: boolean;
1122
+ idempotentHint?: boolean;
1118
1123
  openWorldHint: boolean;
1119
1124
  destructiveHint: boolean;
1120
1125
  }
1126
+ interface McpAuthActionContext {
1127
+ authSource: unknown;
1128
+ defaultAction: string;
1129
+ }
1130
+ type McpAuthAction = string | ((context: McpAuthActionContext) => string);
1131
+ /** Host-selected message and action for terms-acceptance failures. */
1132
+ interface ToolTermsRemediation {
1133
+ message: string;
1134
+ action: string;
1135
+ }
1136
+ /** Host-provided execution state shared by MCP and direct tool callers. */
1137
+ interface ToolExecutionContext {
1138
+ authAction?: McpAuthAction;
1139
+ termsRemediation?: ToolTermsRemediation;
1140
+ signal?: AbortSignal;
1141
+ }
1121
1142
  /**
1122
1143
  * Standard result type for all MCP tools
1123
1144
  */
@@ -1134,11 +1155,6 @@ type ToolResult = {
1134
1155
  type ZodRawShape2 = {
1135
1156
  [k: string]: z.ZodTypeAny;
1136
1157
  };
1137
- interface McpAuthActionContext {
1138
- authSource: unknown;
1139
- defaultAction: string;
1140
- }
1141
- type McpAuthAction = string | ((context: McpAuthActionContext) => string);
1142
1158
  /**
1143
1159
  * Services required to construct the MCP tool surface.
1144
1160
  *
@@ -1168,6 +1184,7 @@ interface CreateMcpServerOptions<TExtra = unknown> {
1168
1184
  metadata: McpServerMetadata;
1169
1185
  services: McpToolServicesProvider<TExtra>;
1170
1186
  authAction?: McpAuthAction;
1187
+ termsRemediation?: ToolTermsRemediation;
1171
1188
  /** Optional caller-owned MCP instructions. GitHits does not provide defaults. */
1172
1189
  instructions?: string;
1173
1190
  /** Controls the guide returned by `quick_start`. */
@@ -1185,6 +1202,7 @@ interface McpToolDescriptor<TSchema extends ZodRawShape2 = ZodRawShape2> {
1185
1202
  declare function getMcpToolDescriptors(): McpToolDescriptor[];
1186
1203
  declare function registerMcpTools<TExtra = unknown>(server: McpServer, options: {
1187
1204
  authAction?: McpAuthAction;
1205
+ termsRemediation?: ToolTermsRemediation;
1188
1206
  services: McpToolServicesProvider<TExtra>;
1189
1207
  traceTool?: McpToolExecutionHook;
1190
1208
  }): void;
@@ -1192,4 +1210,4 @@ declare function registerMcpTools<TExtra = unknown>(server: McpServer, options:
1192
1210
  * Creates the transport-neutral MCP server with injected services.
1193
1211
  */
1194
1212
  declare function createMcpServer<TExtra = unknown>(options: CreateMcpServerOptions<TExtra>): McpServer;
1195
- export { BuildMcpInstructionsOptions, BuildMcpQuickStartOptions, CreateMcpServerOptions, McpAuthAction, McpAuthActionContext, McpRequestContext, McpServerMetadata, McpToolDescriptor, McpToolExecutionHook, McpToolServices, McpToolServicesProvider, buildMcpInstructions, buildMcpQuickStart, createMcpServer, getMcpToolDescriptors, registerMcpTools };
1213
+ export { BuildMcpInstructionsOptions, BuildMcpQuickStartOptions, CreateMcpServerOptions, McpAuthAction, McpAuthActionContext, McpRequestContext, McpServerMetadata, McpToolDescriptor, McpToolExecutionHook, McpToolServices, McpToolServicesProvider, ToolExecutionContext, ToolTermsRemediation, buildMcpInstructions, buildMcpQuickStart, createMcpServer, getMcpToolDescriptors, registerMcpTools };