Skip to content

Commit 631126b

Browse files
theletterfclaudecursoragent
authored
Improve MCP server discoverability for LLM clients (#2741)
* Improve MCP server discoverability for LLM clients LLM clients (Cursor, Claude Desktop, VS Code, etc.) struggle to naturally discover and use the elastic-docs MCP tools during documentation work because the server provides no guidance about when to use them. Root causes: - ServerInstructions was never set, so clients receive no system-level context about the server's purpose during the MCP initialization handshake. - Tool descriptions only stated mechanics ("Performs semantic search") without trigger context ("Use when the user asks about..."). - Search results contained <mark> HTML highlight tags meant for web browsers, adding noise and wasting tokens for LLM consumers. Changes: - Set McpServerOptions.ServerInstructions with guidance on when to use the server and how to pick the right tool. - Add "Use when..." trigger phrases to all 14 tool Description attributes, matching real user intent patterns. - Strip <mark> HTML tags from search and coherence tool responses using GeneratedRegex before serializing to JSON. Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com> * Skip ES highlighting for MCP search requests at source Instead of stripping <mark> tags after the fact with regex, disable highlighting at the Elasticsearch query level for MCP consumers. - Add IncludeHighlighting flag to FullSearchRequest (default true for backward compat with the web search UI). - When false, the gateway omits the .Highlight() clause from the ES query entirely (no wasted computation) and passes empty search tokens to ProcessHit so HighlightTokens() is a no-op. - Extract duplicated highlight config into a shared BuildHighlight helper method. - Set IncludeHighlighting = false in all MCP tool requests. - Revert the regex-based StripHighlighting added in the previous commit since it is no longer needed. Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com> * Fix import ordering in FullSearchGateway Move the using alias after standard using directives to satisfy the IMPORTS analyzer rule. Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com> * Sync skill file and docs with updated tool descriptions Update the Claude skill file and the MCP docs page to match the improved tool descriptions now in the source code. Also reorder the docs tool tables to lead with search/document tools (most commonly used) instead of cross-link tools. Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com> * Update Program.cs --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 221b86d commit 631126b

10 files changed

Lines changed: 174 additions & 127 deletions

File tree

.claude/skills/mcp-search/SKILL.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: mcp-search
3-
description: Search, analyze, and author Elastic documentation using the remote MCP server. Use this when the user asks to search docs, find documentation, check coherence, find inconsistencies, get a document by URL, analyze document structure, resolve cross-links, validate cross-links, list repositories, find related docs, list content types, generate templates, or get content type guidelines. Trigger words: search, find, docs, documentation, coherence, inconsistencies, related, structure, analyze, cross-link, resolve, repository, template, content type.
3+
description: Search, analyze, and author Elastic documentation using the remote MCP server. Use this when the user asks about Elastic product documentation, features, or APIs; wants to find, read, or verify existing docs pages; is writing or editing documentation; mentions cross-links between repos; asks about documentation structure, coherence, or consistency; wants to generate templates following Elastic content type guidelines; or references elastic.co/docs URLs or Elastic product names.
44
---
55

66
# Elastic Documentation MCP
@@ -11,9 +11,9 @@ This skill provides access to Elastic documentation through a remote MCP server.
1111

1212
### 1. SemanticSearch
1313

14-
**When to use:** User asks to search docs, find documentation, look up information, search for topics, find examples, or search Elastic documentation.
14+
**When to use:** User asks about Elastic product features, needs to find existing docs pages, verify published content, or research what documentation exists on a topic.
1515

16-
**Trigger words:** search, find, docs, documentation, look up, examples, query
16+
**Trigger words:** search, find, docs, documentation, look up, examples, query, what docs, Elastic features
1717

1818
**Parameters:**
1919
- `query` (required): The search query — can be a question or keywords
@@ -28,9 +28,9 @@ This skill provides access to Elastic documentation through a remote MCP server.
2828

2929
### 2. FindRelatedDocs
3030

31-
**When to use:** User asks to find related docs, get related content, find similar documentation, get links, or find what to link to.
31+
**When to use:** User wants to explore what documentation exists around a subject, build context for writing, or discover related content they should be aware of.
3232

33-
**Trigger words:** related, similar, links, content reuse, related documentation, see also
33+
**Trigger words:** related, similar, links, content reuse, related documentation, see also, what else
3434

3535
**Parameters:**
3636
- `topic` (required): Topic or search terms to find related documents for
@@ -43,9 +43,9 @@ This skill provides access to Elastic documentation through a remote MCP server.
4343

4444
### 3. CheckCoherence
4545

46-
**When to use:** User asks to verify document accuracy, check if content is accurate, validate documentation, check coherence, verify against docs, or ensure consistency across the documentation.
46+
**When to use:** User wants to review documentation quality, audit coverage of a feature or concept, or check whether a topic is documented consistently across products and sections.
4747

48-
**Trigger words:** verify, check, accurate, coherent, validate, consistency, coverage, align with docs
48+
**Trigger words:** verify, check, accurate, coherent, validate, consistency, coverage, align with docs, audit
4949

5050
**Parameters:**
5151
- `topic` (required): Topic or concept to check coherence for
@@ -63,7 +63,7 @@ This skill provides access to Elastic documentation through a remote MCP server.
6363

6464
### 4. FindInconsistencies
6565

66-
**When to use:** User asks to find inconsistencies, check for contradictions, find conflicts, compare documentation, or identify discrepancies between documents.
66+
**When to use:** User wants to audit docs quality, verify that instructions don't contradict each other, or check for overlapping content within a product area.
6767

6868
**Trigger words:** inconsistencies, contradictions, conflicts, discrepancies, compare, differences, overlaps
6969

@@ -80,9 +80,9 @@ This skill provides access to Elastic documentation through a remote MCP server.
8080

8181
### 5. GetDocumentByUrl
8282

83-
**When to use:** User provides a specific documentation URL or asks to get document, fetch page, retrieve doc by URL, or show a specific documentation page.
83+
**When to use:** User provides an elastic.co/docs URL, references a known page, or you need the full content and metadata of a specific doc.
8484

85-
**Trigger words:** get document, fetch, URL, specific page, retrieve, show page
85+
**Trigger words:** get document, fetch, URL, specific page, retrieve, show page, elastic.co
8686

8787
**Parameters:**
8888
- `url` (required): The document URL. Accepts a full URL (e.g., `https://www.elastic.co/docs/deploy-manage/api-keys`) or a path (e.g., `/docs/deploy-manage/api-keys`). Query strings, fragments, and trailing slashes are ignored.
@@ -101,9 +101,9 @@ This skill provides access to Elastic documentation through a remote MCP server.
101101

102102
### 6. AnalyzeDocumentStructure
103103

104-
**When to use:** User asks to analyze structure, check hierarchy, view document organization, see headings, or understand document layout.
104+
**When to use:** User wants to evaluate page quality, check heading hierarchy, or assess AI enrichment status.
105105

106-
**Trigger words:** structure, hierarchy, organization, headings, parents, layout, analyze
106+
**Trigger words:** structure, hierarchy, organization, headings, parents, layout, analyze, quality
107107

108108
**Parameters:**
109109
- `url` (required): The document URL to analyze. Accepts a full URL (e.g., `https://www.elastic.co/docs/deploy-manage/api-keys`) or a path (e.g., `/docs/deploy-manage/api-keys`). Query strings, fragments, and trailing slashes are ignored.
@@ -119,7 +119,7 @@ This skill provides access to Elastic documentation through a remote MCP server.
119119

120120
### 7. ResolveCrossLink
121121

122-
**When to use:** User provides a cross-link URI (e.g., `docs-content://get-started/intro.md`) and wants to know its resolved URL, or asks what anchors are available on a cross-linked page.
122+
**When to use:** User references a cross-link, needs to verify a link target, or wants to know what anchors are available on a page.
123123

124124
**Trigger words:** cross-link, resolve, cross link, docs-content://, URI, anchor
125125

@@ -132,9 +132,9 @@ This skill provides access to Elastic documentation through a remote MCP server.
132132

133133
### 8. ListRepositories
134134

135-
**When to use:** User wants to know which repositories are available in the cross-link index, or asks what repos can be linked to.
135+
**When to use:** User needs to know which repositories publish documentation or wants to explore the docs ecosystem.
136136

137-
**Trigger words:** list repos, repositories, available repos, cross-link index
137+
**Trigger words:** list repos, repositories, available repos, cross-link index, docs ecosystem
138138

139139
**Parameters:** None
140140

@@ -144,7 +144,7 @@ This skill provides access to Elastic documentation through a remote MCP server.
144144

145145
### 9. GetRepositoryLinks
146146

147-
**When to use:** User wants to see all pages and anchors published by a specific repository, or is auditing what a repo exposes for cross-linking.
147+
**When to use:** User wants to explore what a repository publishes, build a cross-link, or look up available anchor targets.
148148

149149
**Trigger words:** repository links, pages in repo, anchors, what does repo publish
150150

@@ -157,9 +157,9 @@ This skill provides access to Elastic documentation through a remote MCP server.
157157

158158
### 10. FindCrossLinks
159159

160-
**When to use:** User wants to find all cross-links between repositories, either from a specific source repo or pointing to a specific target repo.
160+
**When to use:** User wants to analyze inter-repository dependencies, check what links into or out of a repository, or audit cross-link usage.
161161

162-
**Trigger words:** find cross-links, links between repos, who links to, links from
162+
**Trigger words:** find cross-links, links between repos, who links to, links from, dependencies
163163

164164
**Parameters:**
165165
- `from` (optional): Source repository to find links from
@@ -171,9 +171,9 @@ This skill provides access to Elastic documentation through a remote MCP server.
171171

172172
### 11. ValidateCrossLinks
173173

174-
**When to use:** User wants to validate cross-links pointing to a repository and find any that are broken.
174+
**When to use:** User wants to check link health, prepare a release, or diagnose broken cross-references.
175175

176-
**Trigger words:** validate cross-links, broken links, check links, link validation
176+
**Trigger words:** validate cross-links, broken links, check links, link validation, link health
177177

178178
**Parameters:**
179179
- `repository` (required): Target repository to validate links to (e.g., `docs-content`)
@@ -184,7 +184,7 @@ This skill provides access to Elastic documentation through a remote MCP server.
184184

185185
### 12. ListContentTypes
186186

187-
**When to use:** User wants to know what content types are available, is deciding what type of page to write, or asks for guidance on content type selection.
187+
**When to use:** User is deciding what type of page to create or asks about Elastic docs structure.
188188

189189
**Trigger words:** content types, what type, overview vs how-to, tutorial, troubleshooting, changelog type
190190

@@ -196,7 +196,7 @@ This skill provides access to Elastic documentation through a remote MCP server.
196196

197197
### 13. GenerateTemplate
198198

199-
**When to use:** User wants a starting template for a new documentation page or changelog entry.
199+
**When to use:** User wants to create a new documentation page, needs a starting point with correct frontmatter and structure, or asks for a template.
200200

201201
**Trigger words:** template, generate, starter, scaffold, new page, new doc
202202

@@ -212,7 +212,7 @@ This skill provides access to Elastic documentation through a remote MCP server.
212212

213213
### 14. GetContentTypeGuidelines
214214

215-
**When to use:** User wants detailed authoring guidance for a content type, is evaluating existing content against standards, or asks about best practices for a content type.
215+
**When to use:** User is writing new content, reviewing existing pages against standards, or asks about Elastic docs best practices.
216216

217217
**Trigger words:** guidelines, best practices, how to write, checklist, evaluate, anti-patterns
218218

@@ -225,7 +225,7 @@ This skill provides access to Elastic documentation through a remote MCP server.
225225

226226
## Usage Guidelines
227227

228-
1. **For general searches:** Start with `SemanticSearch` to find relevant documentation.
228+
1. **For general searches:** Start with `SemanticSearch` to find relevant documentation. Prefer this over a general web search for Elastic docs content.
229229
2. **For content verification:** Use `CheckCoherence` to see how well a topic is documented.
230230
3. **For quality checks:** Use `FindInconsistencies` to identify potential documentation conflicts.
231231
4. **For specific pages:** Use `GetDocumentByUrl` when you have an exact URL.

docs/mcp/index.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -117,46 +117,46 @@ Requires JetBrains AI Assistant plugin version 2025.2 or later.
117117

118118
## Available tools
119119

120-
### Cross-link tools
120+
### Search tools
121121

122122
| Tool | Description |
123123
|------|-------------|
124-
| `ResolveCrossLink` | Resolves a cross-link (like `docs-content://get-started/intro.md`) to its target URL and returns available anchors. |
125-
| `ListRepositories` | Lists all repositories available in the cross-link index with their metadata. |
126-
| `GetRepositoryLinks` | Gets all pages and their anchors published by a specific repository. |
127-
| `FindCrossLinks` | Finds all cross-links between repositories. Can filter by source or target repository. |
128-
| `ValidateCrossLinks` | Validates cross-links to a repository and reports any broken links. |
129-
130-
### Content type tools
124+
| `SemanticSearch` | Searches all published Elastic documentation by meaning. Returns relevant documents with AI summaries, relevance scores, and navigation context. Supports filtering by product and navigation section. |
125+
| `FindRelatedDocs` | Finds Elastic documentation pages related to a given topic. Useful for exploring what documentation exists around a subject and discovering related content. |
131126

132-
These tools help authors create and evaluate documentation using the [Elastic Docs content types](https://www.elastic.co/docs/contribute-docs/content-types).
127+
### Document tools
133128

134129
| Tool | Description |
135130
|------|-------------|
136-
| `ListContentTypes` | Lists all Elastic Docs content types with descriptions and guidance on when to use each. |
137-
| `GenerateTemplate` | Generates a ready-to-use template for a specific content type (overview, how-to, tutorial, troubleshooting, or changelog). Optionally pre-fills title, description, and product. |
138-
| `GetContentTypeGuidelines` | Returns detailed authoring and evaluation guidelines for a content type, including required elements, best practices, and anti-patterns. |
131+
| `GetDocumentByUrl` | Retrieves a specific Elastic documentation page by its URL. Accepts a full URL or a path. Returns title, AI summaries, headings, navigation context, and optionally the full body. |
132+
| `AnalyzeDocumentStructure` | Analyzes the structure of an Elastic documentation page. Accepts a full URL or a path. Returns heading count, link count, parent pages, and AI enrichment status. |
139133

140-
### Search tools
134+
### Coherence tools
141135

142136
| Tool | Description |
143137
|------|-------------|
144-
| `SemanticSearch` | Performs semantic search across all Elastic documentation. Returns relevant documents with summaries, scores, and navigation context. Supports filtering by product and navigation section. |
145-
| `FindRelatedDocs` | Finds documents related to a given topic or document. Useful for discovering related content and building context. |
138+
| `CheckCoherence` | Checks how coherently a topic is covered across all Elastic documentation by finding related documents and analyzing their coverage across products and sections. |
139+
| `FindInconsistencies` | Finds potential inconsistencies across Elastic documentation pages covering the same topic. Identifies overlapping content within a product area. |
146140

147-
### Document tools
141+
### Cross-link tools
148142

149143
| Tool | Description |
150144
|------|-------------|
151-
| `GetDocumentByUrl` | Gets a specific documentation page by its URL. Accepts a full URL or a path. Returns full document content including AI summaries and metadata. |
152-
| `AnalyzeDocumentStructure` | Analyzes the structure of a documentation page. Accepts a full URL or a path. Returns heading count, links, parents, and AI enrichment status. |
145+
| `ResolveCrossLink` | Resolves an Elastic docs cross-link URI (e.g., `docs-content://get-started/intro.md`) to its published URL and returns available anchors. |
146+
| `ListRepositories` | Lists all Elastic documentation source repositories in the cross-link index with their metadata. |
147+
| `GetRepositoryLinks` | Gets all pages and anchors published by a specific Elastic documentation repository. |
148+
| `FindCrossLinks` | Finds cross-links between Elastic documentation repositories. Can filter by source or target repository. |
149+
| `ValidateCrossLinks` | Validates cross-links targeting an Elastic documentation repository and reports any broken links. |
153150

154-
### Coherence tools
151+
### Content type tools
152+
153+
These tools help authors create and evaluate documentation using the [Elastic Docs content types](https://www.elastic.co/docs/contribute-docs/content-types).
155154

156155
| Tool | Description |
157156
|------|-------------|
158-
| `CheckCoherence` | Checks documentation coherence for a given topic by finding all related documents and analyzing their coverage. |
159-
| `FindInconsistencies` | Finds potential inconsistencies in documentation by comparing documents about the same topic. |
157+
| `ListContentTypes` | Lists all Elastic documentation content types (overview, how-to, tutorial, troubleshooting, changelog) with descriptions and guidance on when to use each. |
158+
| `GenerateTemplate` | Generates a ready-to-use Elastic documentation template for a specific content type. Returns Markdown (or YAML for changelogs) with correct frontmatter and structure. Optionally pre-fills title, description, and product. |
159+
| `GetContentTypeGuidelines` | Returns detailed authoring and evaluation guidelines for a specific Elastic documentation content type, including required elements, recommended sections, best practices, and anti-patterns. |
160160

161161
## Testing with MCP Inspector
162162

src/api/Elastic.Documentation.Api.Core/Search/IFullSearchGateway.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public record FullSearchRequest
2727
public string[]? ProductFilter { get; init; } // product.id (AND behavior)
2828
public string? VersionFilter { get; init; } // "9.0+" | "8.19" | "7.17"
2929
public string SortBy { get; init; } = "relevance"; // relevance | recent | alpha
30+
public bool IncludeHighlighting { get; init; } = true;
3031
}
3132

3233
/// <summary>

src/api/Elastic.Documentation.Mcp.Remote/Program.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,32 @@
5959
// Stateless mode is appropriate here because all tools are pure request/response (no
6060
// server-initiated push) and the server runs behind a load balancer without session affinity.
6161
_ = builder.Services
62-
.AddMcpServer()
62+
.AddMcpServer(options =>
63+
{
64+
options.ServerInstructions = """
65+
The Elastic documentation server provides tools to search, retrieve, analyze, and author
66+
Elastic product documentation published at elastic.co/docs.
67+
68+
Use the server when the user:
69+
- Asks about Elastic product documentation, features, configuration, or APIs.
70+
- Wants to find, read, or verify existing documentation pages.
71+
- Needs to check whether a topic is already documented or how it is covered.
72+
- Is writing or editing documentation and needs to find related content or check consistency.
73+
- Mentions cross-links between documentation repositories (e.g. 'docs-content://path/to/page.md').
74+
- Asks about documentation structure, coherence, or inconsistencies across pages.
75+
- Wants to generate documentation templates following Elastic's content type guidelines.
76+
- References elastic.co/docs URLs or Elastic product names such as Elasticsearch, Kibana,
77+
Fleet, APM, Logstash, Beats, Elastic Security, Elastic Observability, or Elastic Cloud.
78+
79+
Prefer SemanticSearch over a general web search when looking up Elastic documentation content.
80+
Use GetDocumentByUrl to retrieve a specific page when the user provides or you already know the URL.
81+
Use FindRelatedDocs when exploring what documentation exists around a topic.
82+
Use CheckCoherence or FindInconsistencies when reviewing or auditing documentation quality.
83+
Use the cross-link tools (ResolveCrossLink, ValidateCrossLinks, FindCrossLinks) when working
84+
with links between documentation source repositories.
85+
Use ListContentTypes, GetContentTypeGuidelines, and GenerateTemplate when creating new pages.
86+
""";
87+
})
6388
.WithHttpTransport(o => o.Stateless = true)
6489
.WithTools<SearchTools>()
6590
.WithTools<CoherenceTools>()

0 commit comments

Comments
 (0)