@wyattjoh/rfc 0.3.1 → 0.4.0

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/src/main.ts CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  executeSourceCacheStatus,
20
20
  renderAuthStatus,
21
21
  renderCitationVerification,
22
- renderEvidenceBundle,
22
+ renderResearchResult,
23
23
  renderEstimatedUsd,
24
24
  renderSourceCacheRemove,
25
25
  renderSourceCacheStatus,
@@ -103,20 +103,35 @@ const datatrackerApiUrl = Flag.String("datatracker-api-url").pipe(
103
103
  Flag.optional,
104
104
  );
105
105
 
106
- const question = Flag.String("question").pipe(
107
- Flag.withAlias("q"),
108
- Flag.withDescription("Short question used when standard input is not supplied"),
106
+ const rfcSearchApiUrl = Flag.String("rfc-search-api-url").pipe(
107
+ Flag.withDescription(
108
+ "RFC full-text search API base URL, overriding RFC_SEARCH_API_URL (requires a search key)",
109
+ ),
109
110
  Flag.optional,
110
111
  );
111
112
 
112
- const questionArgument = Argument.String("question").pipe(
113
- Argument.withDescription("Question to research when standard input is not supplied"),
114
- Argument.optional,
113
+ const rfcSearchApiKey = Flag.String("rfc-search-api-key").pipe(
114
+ Flag.withDescription(
115
+ "Search-only key enabling full-text topic discovery, overriding RFC_SEARCH_API_KEY",
116
+ ),
117
+ Flag.optional,
118
+ );
119
+
120
+ const questions = Flag.String("question").pipe(
121
+ Flag.withAlias("q"),
122
+ Flag.withDescription("Question to research; repeat one to four times, one per fact"),
123
+ Flag.between(0, 4),
124
+ );
125
+
126
+ const researchRfcs = Flag.String("rfc").pipe(
127
+ Flag.withAlias("r"),
128
+ Flag.withDescription("Published RFC identifier to search; repeat up to four times"),
129
+ Flag.between(0, 4),
115
130
  );
116
131
 
117
132
  const rfc = Flag.String("rfc").pipe(
118
133
  Flag.withAlias("r"),
119
- Flag.withDescription("Known RFC identifier for a short interactive request"),
134
+ Flag.withDescription("Published RFC identifier containing the quotation"),
120
135
  Flag.optional,
121
136
  );
122
137
 
@@ -132,7 +147,7 @@ const rfcArgument = Argument.String("rfc").pipe(
132
147
  );
133
148
 
134
149
  const searchTerms = Flag.String("search-term").pipe(
135
- Flag.withDescription("Ordered topic-discovery term; repeat one to four times"),
150
+ Flag.withDescription("Ordered topic-discovery term; repeat up to four times"),
136
151
  Flag.between(0, 4),
137
152
  );
138
153
 
@@ -294,6 +309,11 @@ const loopbackHosts = new Set(["localhost", "127.0.0.1", "[::1]"]);
294
309
  * @returns The value unchanged when it is safe to use.
295
310
  * @throws InvalidInputError when the URL is malformed or cleartext off-host.
296
311
  */
312
+ const nonEmptyEnv = (name: string): string | undefined => {
313
+ const value = process.env[name];
314
+ return value === undefined || value.trim().length === 0 ? undefined : value;
315
+ };
316
+
297
317
  const secureEndpointOverride = (flag: string, value: string | undefined): string | undefined => {
298
318
  if (value === undefined) return undefined;
299
319
  const url = URL.parse(value);
@@ -320,7 +340,9 @@ const decodeCitationRequest = (input: unknown) => {
320
340
  try {
321
341
  return decodeCitationVerificationRequest(input);
322
342
  } catch {
323
- throw new InvalidInputError({ reason: "Citation input must use schema version 2" });
343
+ throw new InvalidInputError({
344
+ reason: `Citation input must use schema version ${schemaVersion}`,
345
+ });
324
346
  }
325
347
  };
326
348
 
@@ -402,6 +424,8 @@ const makeApplication = (dependencies: RfcCliDependencies) => {
402
424
  selectedCacheDirectory: string,
403
425
  selectedDatatrackerApiUrl: Option.Option<string>,
404
426
  selectedTypeSafeApiUrl: Option.Option<string>,
427
+ selectedRfcSearchApiUrl: Option.Option<string> = Option.none(),
428
+ selectedRfcSearchApiKey: Option.Option<string> = Option.none(),
405
429
  ): RfcOperationOptions => ({
406
430
  cacheDirectory: selectedCacheDirectory,
407
431
  datatrackerApiUrl: secureEndpointOverride(
@@ -412,6 +436,14 @@ const makeApplication = (dependencies: RfcCliDependencies) => {
412
436
  "--typesafe-api-url",
413
437
  Option.getOrUndefined(selectedTypeSafeApiUrl),
414
438
  ),
439
+ // A flag beats the environment so one invocation can override a shell that
440
+ // configured search globally, matching how the other endpoint flags behave.
441
+ rfcSearchApiUrl: secureEndpointOverride(
442
+ "--rfc-search-api-url",
443
+ Option.getOrUndefined(selectedRfcSearchApiUrl) ?? nonEmptyEnv("RFC_SEARCH_API_URL"),
444
+ ),
445
+ rfcSearchApiKey:
446
+ Option.getOrUndefined(selectedRfcSearchApiKey) ?? nonEmptyEnv("RFC_SEARCH_API_KEY"),
415
447
  });
416
448
 
417
449
  const sourceCacheStatusCommand = Command.make(
@@ -478,6 +510,8 @@ const makeApplication = (dependencies: RfcCliDependencies) => {
478
510
  {
479
511
  cacheDirectory,
480
512
  datatrackerApiUrl,
513
+ rfcSearchApiUrl,
514
+ rfcSearchApiKey,
481
515
  format,
482
516
  rfc,
483
517
  rfcArgument,
@@ -514,7 +548,7 @@ const makeApplication = (dependencies: RfcCliDependencies) => {
514
548
  flags.quoteArgument,
515
549
  );
516
550
  return decodeCitationRequest({
517
- schemaVersion: 2,
551
+ schemaVersion,
518
552
  rfc: selectedRfc,
519
553
  claim: selectedClaim,
520
554
  quote: selectedQuote,
@@ -528,7 +562,13 @@ const makeApplication = (dependencies: RfcCliDependencies) => {
528
562
  try: () =>
529
563
  executeCitationVerification(
530
564
  request,
531
- operationOptions(flags.cacheDirectory, flags.datatrackerApiUrl, flags.typeSafeApiUrl),
565
+ operationOptions(
566
+ flags.cacheDirectory,
567
+ flags.datatrackerApiUrl,
568
+ flags.typeSafeApiUrl,
569
+ flags.rfcSearchApiUrl,
570
+ flags.rfcSearchApiKey,
571
+ ),
532
572
  dependencies,
533
573
  ),
534
574
  catch: (error) => error,
@@ -560,11 +600,11 @@ const makeApplication = (dependencies: RfcCliDependencies) => {
560
600
  {
561
601
  cacheDirectory,
562
602
  datatrackerApiUrl,
603
+ rfcSearchApiUrl,
604
+ rfcSearchApiKey,
563
605
  format,
564
- question,
565
- questionArgument,
566
- rfc,
567
- rfcArgument,
606
+ questions,
607
+ rfcs: researchRfcs,
568
608
  searchTerms,
569
609
  typeSafeApiUrl,
570
610
  },
@@ -577,33 +617,24 @@ const makeApplication = (dependencies: RfcCliDependencies) => {
577
617
  const request =
578
618
  standardInput.trim().length > 0
579
619
  ? decodeResearchInput(standardInput)
580
- : (() => {
581
- const selectedQuestion = resolveRequiredArgumentInput(
582
- "--question",
583
- flags.question,
584
- flags.questionArgument,
585
- );
586
- const selectedRfc = resolveArgumentInput("--rfc", flags.rfc, flags.rfcArgument);
587
- return selectedRfc === undefined
588
- ? decodeResearchRequest({
589
- schemaVersion,
590
- question: selectedQuestion,
591
- rfc: null,
592
- searchTerms: flags.searchTerms,
593
- })
594
- : decodeResearchRequest({
595
- schemaVersion,
596
- question: selectedQuestion,
597
- rfc: selectedRfc,
598
- searchTerms: flags.searchTerms.length === 0 ? undefined : flags.searchTerms,
599
- });
600
- })();
620
+ : decodeResearchRequest({
621
+ schemaVersion,
622
+ questions: flags.questions,
623
+ ...(flags.rfcs.length === 0 ? {} : { rfcs: flags.rfcs }),
624
+ ...(flags.searchTerms.length === 0 ? {} : { searchTerms: flags.searchTerms }),
625
+ });
601
626
 
602
627
  const result = yield* Effect.tryPromise({
603
628
  try: () =>
604
629
  executeResearch(
605
630
  request,
606
- operationOptions(flags.cacheDirectory, flags.datatrackerApiUrl, flags.typeSafeApiUrl),
631
+ operationOptions(
632
+ flags.cacheDirectory,
633
+ flags.datatrackerApiUrl,
634
+ flags.typeSafeApiUrl,
635
+ flags.rfcSearchApiUrl,
636
+ flags.rfcSearchApiKey,
637
+ ),
607
638
  dependencies,
608
639
  ),
609
640
  catch: (error) => error,
@@ -611,20 +642,21 @@ const makeApplication = (dependencies: RfcCliDependencies) => {
611
642
  yield* writeWarnings(result.warnings);
612
643
  yield* writeStdout(
613
644
  resolveOutputFormat(flags.format, standardInput.trim().length > 0) === "human"
614
- ? renderEvidenceBundle(result.value)
645
+ ? renderResearchResult(result.value)
615
646
  : JSON.stringify(result.value),
616
647
  );
617
648
  }),
618
649
  ).pipe(
619
- Command.withDescription("Research an RFC question from versioned JSON input"),
650
+ Command.withDescription("Research RFC questions from flags or versioned JSON input"),
620
651
  Command.withExamples([
621
652
  {
622
653
  command: "rfc research < question.json",
623
654
  description: "Use canonical JSON from standard input",
624
655
  },
625
656
  {
626
- command: 'rfc research "What does RFC 9110 require?" RFC9110',
627
- description: "Use human-friendly positional arguments when standard input is empty",
657
+ command:
658
+ 'rfc research -q "What does the 429 status code mean?" -q "Which header says how long to wait?" -r RFC6585 -r RFC9110',
659
+ description: "Research several questions against named RFCs when standard input is empty",
628
660
  },
629
661
  ]),
630
662
  );
@@ -718,12 +750,18 @@ const makeApplication = (dependencies: RfcCliDependencies) => {
718
750
 
719
751
  const mcpCommand = Command.make(
720
752
  "mcp",
721
- { cacheDirectory, datatrackerApiUrl, typeSafeApiUrl },
753
+ { cacheDirectory, datatrackerApiUrl, typeSafeApiUrl, rfcSearchApiUrl, rfcSearchApiKey },
722
754
  Effect.fn(function* (flags) {
723
755
  yield* Effect.tryPromise({
724
756
  try: () =>
725
757
  runRfcMcpServer(
726
- operationOptions(flags.cacheDirectory, flags.datatrackerApiUrl, flags.typeSafeApiUrl),
758
+ operationOptions(
759
+ flags.cacheDirectory,
760
+ flags.datatrackerApiUrl,
761
+ flags.typeSafeApiUrl,
762
+ flags.rfcSearchApiUrl,
763
+ flags.rfcSearchApiKey,
764
+ ),
727
765
  dependencies,
728
766
  (error) =>
729
767
  dependencies.writeStderr(`${JSON.stringify(toRfcOperationErrorEnvelope(error))}\n`),
package/src/mcp.ts CHANGED
@@ -1,17 +1,25 @@
1
1
  import {
2
2
  CitationVerificationResultSchema,
3
- EvidenceBundleSchema,
3
+ ResearchResultSchema,
4
4
  InvalidInputError,
5
5
  RfcSourceCacheRemoveResultSchema,
6
6
  RfcSourceCacheStatusSchema,
7
7
  datatrackerTopicSearchTermLimit,
8
8
  datatrackerTopicSearchTermMaximumCharacters,
9
+ retrievalPolicy,
9
10
  schemaVersion,
11
+ type CitationVerificationResult,
12
+ type ResearchResult,
10
13
  } from "@wyattjoh/rfc-core";
11
14
  import { McpServer, type CallToolResult } from "@modelcontextprotocol/server";
12
15
  import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
13
16
  import { Schema } from "effect";
14
- import { rfcAgentToolMetadata, rfcMcpAgentReferenceUri, rfcMcpInstructions } from "./agent-surface";
17
+ import {
18
+ rfcAgentParameterDescriptions as descriptions,
19
+ rfcAgentToolMetadata,
20
+ rfcMcpAgentReferenceUri,
21
+ rfcMcpInstructions,
22
+ } from "./agent-surface";
15
23
  import { AuthStatusSchema } from "./credentials";
16
24
  import {
17
25
  executeAuthStatus,
@@ -21,7 +29,7 @@ import {
21
29
  executeSourceCacheStatus,
22
30
  renderAuthStatus,
23
31
  renderCitationVerification,
24
- renderEvidenceBundle,
32
+ renderResearchResult,
25
33
  renderSourceCacheRemove,
26
34
  renderSourceCacheStatus,
27
35
  toRfcOperationErrorEnvelope,
@@ -38,35 +46,42 @@ export { rfcAgentToolMetadata, rfcMcpAgentReferenceUri, rfcMcpInstructions } fro
38
46
  */
39
47
  export const rfcMcpAgentReference = `# RFC MCP agent workflow
40
48
 
41
- This MCP server is the complete RFC research backend. It owns live RFC discovery, RFC currency traversal, canonical RFC Editor source retrieval, bounded evidence selection, citation verification, source caching, provider credential status, and usage accounting. Do not answer RFC claims from memory or another provider.
49
+ This MCP server is the complete RFC research backend. It owns live RFC discovery, RFC currency traversal, canonical RFC Editor source retrieval, relevance ranking, passage selection, citation verification, source caching, provider credential status, and usage accounting. Do not answer RFC claims from memory or another provider.
42
50
 
43
- ## Bounded workflow
51
+ ## Workflow
44
52
 
45
- For one atomic question:
53
+ 1. Call \`rfc_research\` once per user request. Put each fact you need in \`questions\` (up to four); each question is answered independently against the same candidate RFCs.
54
+ 2. Pass \`rfcs\` when you know the RFC numbers and \`searchTerms\` when you do not; both may be combined. Named RFCs, their current successors, and topic matches form one candidate pool.
55
+ 3. Answer from the returned passages. Each passage names its RFC, section, verdict, and UTF-8 byte range. Cite only the RFC and section shown.
56
+ 4. When a question is not found, you may make one follow-up call with other \`rfcs\` or \`searchTerms\`. Never re-research or re-verify returned passages.
46
57
 
47
- 1. Call \`rfc_research_known_rfc\` when the RFC is known, otherwise call \`rfc_research_topic\` with one to four deliberate ordered technical search terms.
48
- 2. Make at most one targeted follow-up research call, and only when the first result has neither usable accepted evidence nor a review candidate. Never loop by rephrasing a valid result to chase \`answered\` or higher confidence.
49
- 3. When accepted evidence or a review candidate is returned, answer from that result and stop. Quote accepted evidence unchanged with provenance. Quote a review candidate only as explicitly unaccepted or \`needs_review\`.
50
- 4. Never call \`rfc_verify_citation\` after research to re-check returned evidence, normalize formatting, or obtain alternate provenance. Use it only for a user-supplied quotation or an explicitly requested distinct paraphrase check, at most twice.
51
- 5. Stop after the budget. Preserve non-answer statuses and typed operational failures.
58
+ ## Result
52
59
 
53
- For up to two explicit independently answerable questions, use one research call per question and keep their inputs and outputs separate. Do not invent a split for an ambiguous request; preserve \`needs_split\`.
60
+ For each question the result lists hits: an RFC, its \`role\` (\`requested\`, \`current\` successor of a requested RFC, or \`discovered\` by topic search), its \`relevance\`, a \`verdict\`, and one to three exact passages. \`found: false\` means none of the \`searched\` RFCs contained an answer.
54
61
 
55
- ## Tools
62
+ Verdicts use citation-check semantics:
56
63
 
57
- ### rfc_research_known_rfc
64
+ - \`supports\`: the passage states the answer or directly implies it.
65
+ - \`partial\`: the passage answers only part of the question.
66
+ - \`says_nothing\`: the passage does not address the question.
67
+ - \`contradicts\`: the passage states the opposite of what the question presumes.
58
68
 
59
- Research one atomic question against a known published RFC. The server performs bounded live metadata lookup and currency traversal, researches requested and applicable current RFC contexts independently, and never silently substitutes a successor.
69
+ A \`current\` hit comes from the RFC that replaced the one named. Keep it distinct from the requested RFC and never silently substitute a successor. \`currency\` reports each named RFC's current successors and the relationship path.
60
70
 
61
- Inputs are \`question\` and \`rfc\`. Use the exact RFC identifier, such as \`RFC9110\`.
71
+ ## Tools
62
72
 
63
- ### rfc_research_topic
73
+ ### rfc_research
64
74
 
65
- Discover and research published RFCs for one atomic topic question. Inputs are \`question\` and \`searchTerms\`. Supply one to four ordered non-empty terms, each no longer than ${datatrackerTopicSearchTermMaximumCharacters} characters. Terms are transmitted verbatim in Datatracker query URLs and may appear in diagnostics, errors, and upstream access logs. Do not generate hidden terms, rewrite the caller's phrases, or send the natural-language question upstream unless it was explicitly chosen as a term.
75
+ Inputs are \`questions\`, optional \`rfcs\`, and optional \`searchTerms\`; at least one of \`rfcs\` or \`searchTerms\` is required. Supply one to four ordered non-empty terms, each no longer than ${datatrackerTopicSearchTermMaximumCharacters} characters. Each term is matched as a literal case-insensitive substring of an RFC title or abstract, so use short noun phrases such as \`DNS over TLS\`; a sentence fragment such as \`DNS over TLS default port\` matches nothing. If the operator enabled optional full-text search, terms additionally match RFC keywords and body text. Terms are transmitted verbatim in upstream query URLs and may appear in diagnostics, errors, and upstream access logs. Never include private or user-specific details in a term, and do not send a natural-language question upstream unless it was explicitly chosen as a term.
66
76
 
67
77
  ### rfc_verify_citation
68
78
 
69
- Verify one factual claim against one exact RFC quotation. Inputs are \`rfc\`, \`claim\`, \`quote\`, and optional \`offset\`. The offset is an absolute UTF-8 byte offset into the exact source identified by \`sourceHash\`, not a JavaScript string index. Copy it from research provenance or omit it for a unique quotation. Never guess wording or offsets.
79
+ Verify one factual claim against one exact RFC quotation. Inputs are \`rfc\`, \`claim\`, \`quote\`, and optional \`offset\`. The offset is an absolute UTF-8 byte offset into the exact source identified by \`sourceHash\`, not a JavaScript string index. Copy it from a research quote range or omit it for a unique quotation. Never guess wording or offsets. Use it only for a user-supplied quotation or an explicitly requested check.
80
+
81
+ - \`verified\`: the exact present quotation supports the claim.
82
+ - \`unsupported\`: the quotation does not establish the claim.
83
+ - \`contradicted\`: the quotation conflicts with the claim.
84
+ - \`fabricated\`: the supplied quotation is absent from the authoritative source.
70
85
 
71
86
  ### rfc_source_cache_status
72
87
 
@@ -80,46 +95,23 @@ Remove one named RFC source-cache entry without network access. This destructive
80
95
 
81
96
  Report only whether the stable TypeSafe credential identity is configured. The MCP never accepts, returns, adds, or removes credentials. If missing, ask the human operator to run \`rfc auth login\` outside MCP.
82
97
 
83
- ## Research statuses
84
-
85
- - \`answered\`: accepted direct evidence with no disqualifying uncertainty.
86
- - \`partial\`: only part of the question or RFC currency coverage is established.
87
- - \`unsupported\`: bounded research found no accepted answering evidence.
88
- - \`needs_review\`: confidence is low, evidence conflicts, discovery is empty, or RFC currency is uncertain.
89
- - \`needs_split\`: the question is compound and requires atomic questions.
90
-
91
- A valid non-answer status is a successful tool result, not an operational failure. Review candidates are canonical source passages surfaced for bounded review but are not accepted evidence. Never turn them into unqualified claims.
92
-
93
- ## Citation verdicts
94
-
95
- - \`verified\`: the exact present quotation supports the claim.
96
- - \`unsupported\`: the quotation does not establish the claim.
97
- - \`contradicted\`: the quotation conflicts with the claim.
98
- - \`fabricated\`: the supplied quotation is absent from the authoritative source.
99
-
100
- Only accepted research evidence or a \`verified\` citation supports an unqualified factual claim. If a quote is fabricated, make at most one research call to locate current wording and at most one verification call for that replacement.
101
-
102
- ## Provenance and RFC currency
103
-
104
- Preserve exact quotes, RFC identifiers, requested/current context roles, relationship paths, nullable section labels, canonical source URLs, source hashes, \`offsetUnit: "utf8-byte"\`, and byte offsets. Do not answer a question about the requested RFC with current-context evidence without explicitly explaining the distinction.
105
-
106
98
  ## Fail-closed operations
107
99
 
108
- Operational failures are returned as MCP tool errors containing the safe version-two RFC error envelope. Report the code and stop. In particular:
100
+ Operational failures are returned as MCP tool errors containing the safe version-three RFC error envelope. Report the code and stop. In particular:
109
101
 
110
102
  - \`invalid_input\`: correct the bounded tool input.
111
103
  - \`credential_missing\`: ask the human to run \`rfc auth login\`.
112
104
  - \`credential_store_unavailable\` or \`credential_access_denied\`: ask the human to unlock or authorize the OS credential store; never use plaintext fallback.
113
105
  - \`discovery_failed\`: report the Datatracker failure; do not invent or use stale metadata.
114
106
  - \`source_cache_failed\`, \`source_fetch_failed\`, or \`source_revalidation_failed\`: report the authoritative source failure; never serve stale text or substitute another representation.
115
- - \`rfc_not_found\`: correct the exact identifier or use topic discovery with explicit terms.
107
+ - \`rfc_not_found\`: correct the exact identifier or use \`searchTerms\`.
116
108
  - \`decision_model_failed\`: report the bounded provider failure; do not switch provider or model.
117
109
  - \`citation_quote_ambiguous\` or \`citation_offset_mismatch\`: copy an exact research offset or stop; never guess.
118
110
  - \`internal_error\` or \`configuration_error\`: report an operational failure rather than asserting an answer.
119
111
 
120
112
  ## Privacy, cost, and cache behavior
121
113
 
122
- Questions and model responses are request-local and are not persisted. Topic search terms are sent to Datatracker and can be retained in upstream logs. Canonical RFC Editor text is cached per RFC with integrity and validator metadata. Fresh entries are reused; stale entries must revalidate successfully.
114
+ Questions and model responses are request-local and are not persisted. Topic search terms are sent to Datatracker, and to the IETF RFC search service when the operator enabled it, and can be retained in upstream logs. When \`retrieval.topicSearchFallback\` is true, full-text search was configured but failed and discovery matched titles and abstracts only, so an empty result is less conclusive than usual. Canonical RFC Editor text is cached per RFC with integrity and validator metadata. Fresh entries are reused; stale entries must revalidate successfully.
123
115
 
124
116
  Research and citation results report provider input tokens and estimated input cost. A null estimate means unavailable, not zero. Each successful semantic operation updates per-user usage totals. If accounting fails, the tool still succeeds and adds a \`usage_accounting_failed\` warning; do not retry a successful paid operation because of that warning.
125
117
  `;
@@ -127,55 +119,43 @@ Research and citation results report provider input tokens and estimated input c
127
119
  const describedString = (description: string) =>
128
120
  Schema.NonEmptyString.pipe(Schema.annotate({ description }));
129
121
 
130
- const KnownRfcResearchInputSchema = Schema.Struct({
131
- question: describedString("One independently answerable RFC question"),
132
- rfc: describedString("Exact published RFC identifier, for example RFC9110"),
133
- });
134
-
135
122
  const TopicSearchTermSchema = Schema.String.check(
136
123
  Schema.isMinLength(1),
137
124
  Schema.isMaxLength(datatrackerTopicSearchTermMaximumCharacters),
138
- ).pipe(
139
- Schema.annotate({
140
- description:
141
- "Deliberate topic-discovery term sent verbatim in Datatracker query URLs and upstream logs",
142
- }),
143
- );
144
-
145
- const TopicResearchInputSchema = Schema.Struct({
146
- question: describedString("One independently answerable topic question"),
147
- searchTerms: Schema.Array(TopicSearchTermSchema)
148
- .check(Schema.isMinLength(1), Schema.isMaxLength(datatrackerTopicSearchTermLimit))
149
- .pipe(
150
- Schema.annotate({
151
- description: "One to four ordered topic-discovery terms; preserve caller order",
152
- }),
153
- ),
125
+ ).pipe(Schema.annotate({ description: descriptions.searchTerm }));
126
+
127
+ const ResearchInputSchema = Schema.Struct({
128
+ questions: Schema.Array(describedString(descriptions.question))
129
+ .check(Schema.isMinLength(1), Schema.isMaxLength(retrievalPolicy.maxQuestions))
130
+ .pipe(Schema.annotate({ description: descriptions.questions })),
131
+ rfcs: Schema.optionalKey(
132
+ Schema.Array(describedString(descriptions.rfc))
133
+ .check(Schema.isMinLength(1), Schema.isMaxLength(retrievalPolicy.maxRequestedRfcs))
134
+ .pipe(Schema.annotate({ description: descriptions.rfcs })),
135
+ ),
136
+ searchTerms: Schema.optionalKey(
137
+ Schema.Array(TopicSearchTermSchema)
138
+ .check(Schema.isMinLength(1), Schema.isMaxLength(datatrackerTopicSearchTermLimit))
139
+ .pipe(Schema.annotate({ description: descriptions.searchTerms })),
140
+ ),
154
141
  });
155
142
 
156
143
  const CitationInputSchema = Schema.Struct({
157
- rfc: describedString("Exact published RFC identifier containing the quotation"),
158
- claim: describedString("One factual claim to check"),
159
- quote: describedString("Exact unchanged RFC quotation"),
144
+ rfc: describedString(descriptions.citationRfc),
145
+ claim: describedString(descriptions.claim),
146
+ quote: describedString(descriptions.quote),
160
147
  offset: Schema.optionalKey(
161
- Schema.Natural.pipe(
162
- Schema.annotate({
163
- description:
164
- "Absolute UTF-8 byte offset copied from research provenance; omit for a unique quotation",
165
- }),
166
- ),
148
+ Schema.Natural.pipe(Schema.annotate({ description: descriptions.offset })),
167
149
  ),
168
150
  });
169
151
 
170
152
  const RfcInputSchema = Schema.Struct({
171
- rfc: describedString("Exact named RFC source-cache entry, for example RFC9110"),
153
+ rfc: describedString(descriptions.cacheRfc),
172
154
  });
173
155
 
174
156
  const SourceCacheRemoveInputSchema = Schema.Struct({
175
- rfc: describedString("Exact named RFC source-cache entry, for example RFC9110"),
176
- confirm: Schema.Literal(true).pipe(
177
- Schema.annotate({ description: "Must be true to confirm removal of the named cache entry" }),
178
- ),
157
+ rfc: describedString(descriptions.cacheRfc),
158
+ confirm: Schema.Literal(true).pipe(Schema.annotate({ description: descriptions.confirm })),
179
159
  });
180
160
 
181
161
  const EmptyInputSchema = Schema.Struct({});
@@ -194,6 +174,12 @@ const toMcpSchema = <S extends Schema.ConstraintDecoder<unknown> & Schema.Constr
194
174
  };
195
175
  };
196
176
 
177
+ const renderAgentResearch = (value: ResearchResult): string =>
178
+ renderResearchResult(value, { audience: "agent" });
179
+
180
+ const renderAgentCitation = (value: CitationVerificationResult): string =>
181
+ renderCitationVerification(value, { audience: "agent" });
182
+
197
183
  const warningContent = (warnings: ReadonlyArray<RfcOperationWarning>) =>
198
184
  warnings.map((warning) => ({ type: "text" as const, text: JSON.stringify(warning) }));
199
185
 
@@ -240,7 +226,7 @@ export const createRfcMcpServer = (
240
226
  {
241
227
  title: "RFC MCP agent workflow",
242
228
  description:
243
- "Reference for non-answer statuses, failures, citation repair, provenance, privacy, cache, and cost; skip for ordinary research",
229
+ "Reference for result fields, verdicts, failures, provenance, privacy, cache, and cost; skip for ordinary research",
244
230
  mimeType: "text/markdown",
245
231
  },
246
232
  async (uri) => ({
@@ -255,44 +241,28 @@ export const createRfcMcpServer = (
255
241
  );
256
242
 
257
243
  server.registerTool(
258
- rfcAgentToolMetadata.researchKnownRfc.name,
259
- {
260
- title: rfcAgentToolMetadata.researchKnownRfc.title,
261
- description: rfcAgentToolMetadata.researchKnownRfc.description,
262
- inputSchema: toMcpSchema(KnownRfcResearchInputSchema),
263
- outputSchema: toMcpSchema(EvidenceBundleSchema),
264
- annotations: rfcAgentToolMetadata.researchKnownRfc.annotations,
265
- },
266
- async ({ question, rfc }) => {
267
- try {
268
- return semanticSuccess(
269
- await executeResearch({ schemaVersion, question, rfc }, options, dependencies),
270
- renderEvidenceBundle,
271
- );
272
- } catch (error) {
273
- return toolError(error);
274
- }
275
- },
276
- );
277
-
278
- server.registerTool(
279
- rfcAgentToolMetadata.researchTopic.name,
244
+ rfcAgentToolMetadata.research.name,
280
245
  {
281
- title: rfcAgentToolMetadata.researchTopic.title,
282
- description: rfcAgentToolMetadata.researchTopic.description,
283
- inputSchema: toMcpSchema(TopicResearchInputSchema),
284
- outputSchema: toMcpSchema(EvidenceBundleSchema),
285
- annotations: rfcAgentToolMetadata.researchTopic.annotations,
246
+ title: rfcAgentToolMetadata.research.title,
247
+ description: rfcAgentToolMetadata.research.description,
248
+ inputSchema: toMcpSchema(ResearchInputSchema),
249
+ outputSchema: toMcpSchema(ResearchResultSchema),
250
+ annotations: rfcAgentToolMetadata.research.annotations,
286
251
  },
287
- async ({ question, searchTerms }) => {
252
+ async ({ questions, rfcs, searchTerms }) => {
288
253
  try {
289
254
  return semanticSuccess(
290
255
  await executeResearch(
291
- { schemaVersion, question, rfc: null, searchTerms },
256
+ {
257
+ schemaVersion,
258
+ questions,
259
+ ...(rfcs === undefined ? {} : { rfcs }),
260
+ ...(searchTerms === undefined ? {} : { searchTerms }),
261
+ },
292
262
  options,
293
263
  dependencies,
294
264
  ),
295
- renderEvidenceBundle,
265
+ renderAgentResearch,
296
266
  );
297
267
  } catch (error) {
298
268
  return toolError(error);
@@ -317,7 +287,7 @@ export const createRfcMcpServer = (
317
287
  options,
318
288
  dependencies,
319
289
  ),
320
- renderCitationVerification,
290
+ renderAgentCitation,
321
291
  );
322
292
  } catch (error) {
323
293
  return toolError(error);