Skip to content

[azsdk-cli] add tsp list_topics and tsp get_topic_docs tools (mcp only)#12007

Closed
chrisradek wants to merge 3 commits into
Azure:mainfrom
chrisradek:azsdk-tsp-list-topics
Closed

[azsdk-cli] add tsp list_topics and tsp get_topic_docs tools (mcp only)#12007
chrisradek wants to merge 3 commits into
Azure:mainfrom
chrisradek:azsdk-tsp-list-topics

Conversation

@chrisradek
Copy link
Copy Markdown
Member

Resolves #11679

This PR adds 2 new MCP tools whose purpose is to allow retrieving TypeSpec and TypeSpec Azure documentation.

azsdk_list_typespec_topics

This tool returns a list of "topics" that the agent can request documentation for (e.g. typespec-language-basics, typespec-azure-clients-how-tos) along with their descriptions.

Currently, the TypeSpec/TypeSpec Azure doc websites have been updated to generate these topics whenever they are built:

azsdk_get_typespec_topics_docs

This tool takes in a list of "topics" (must be a topic returned by list_typespec_topics), and returns the documentation for those topics.

The documentation is hosted on the TypeSpec/TypeSpec Azure doc websites in llms-full.txt format - big markdown files.

Why 2 tools?

Trying to fit all the content currently spread across multiple llms-full.txt files would take hundreds of thousands of tokens - overwhelming a lot of context windows today. In my earlier testing, I found that it was also helpful to give targeted documentation. For example, only giving the azure core docs when working on a data plane service, instead of the ARM docs too.

@github-actions github-actions Bot added the azsdk-cli Issues related to Azure/azure-sdk-tools::tools/azsdk-cli label Sep 9, 2025
@chrisradek chrisradek marked this pull request as ready for review September 9, 2025 05:14
Copilot AI review requested due to automatic review settings September 9, 2025 05:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds two new MCP tools to enable retrieving TypeSpec and TypeSpec Azure documentation. The tools provide a way to list available documentation topics and fetch their content, allowing for targeted documentation retrieval instead of overwhelming context windows with all available content.

  • Adds azsdk_list_typespec_topics tool to list available documentation topics with descriptions
  • Adds azsdk_get_typespec_topics_docs tool to fetch documentation content for specified topics
  • Implements a TypeSpecDocsService with caching and thread-safe operations

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
TspInitTool.cs Adds two new MCP tools with dependency injection for TypeSpecDocsService
TypeSpecDocsService.cs Core service implementing documentation fetching with caching and concurrency management
ServiceRegistrations.cs Registers HTTP client and TypeSpecDocsService in DI container
TypeSpecTopicDoc.cs Model for topic documentation content
TypeSpecTopic.cs Model for topic metadata
ListTypeSpecTopicsResponse.cs Response model for listing topics
GetTypeSpecTopicsDocsResponse.cs Response model for topic documentation
LlmsJsonItem.cs Model for parsing llms.json files
TspInitToolTest.cs Updates test constructor calls to include new service dependency
TypeSpecDocsServiceTests.cs Comprehensive test suite for the new service

Comment on lines +193 to +204
var task = inflightRequests.GetOrAdd(url, async (urlKey) =>
{
try
{
using var httpClient = httpClientFactory.CreateClient();
var response = await httpClient.GetStringAsync(urlKey, ct);
return response;
}
finally
{
// Remove from in-flight when done
inflightRequests.TryRemove(urlKey, out _);
Copy link

Copilot AI Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lambda function parameter name urlKey shadows the outer variable url. This could lead to confusion and potential bugs. Use the outer url parameter directly or choose a different parameter name.

Suggested change
var task = inflightRequests.GetOrAdd(url, async (urlKey) =>
{
try
{
using var httpClient = httpClientFactory.CreateClient();
var response = await httpClient.GetStringAsync(urlKey, ct);
return response;
}
finally
{
// Remove from in-flight when done
inflightRequests.TryRemove(urlKey, out _);
var task = inflightRequests.GetOrAdd(url, async (dedupUrl) =>
{
try
{
using var httpClient = httpClientFactory.CreateClient();
var response = await httpClient.GetStringAsync(dedupUrl, ct);
return response;
}
finally
{
// Remove from in-flight when done
inflightRequests.TryRemove(dedupUrl, out _);

Copilot uses AI. Check for mistakes.
Comment on lines +79 to +81
// DI is causing `sources` to always be an empty enumerable instead of null when not provided
var sourceArray = sources?.ToArray();
tspDocSources = (sourceArray?.Length > 0) ? sourceArray : defaultTspDocSources;
Copy link

Copilot AI Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The comment indicates a workaround for a DI issue. Consider using a more explicit approach like checking sources.Any() or implementing a proper factory pattern to handle this dependency injection concern more clearly.

Copilot uses AI. Check for mistakes.
fetchTasks.Add(FetchTopicContentAsync(topic, contentUrl, ct));
}

if (unknownTopics.Count != 0)
Copy link

Copilot AI Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Use .Any() instead of .Count != 0 for better readability and potential performance benefits when checking if a collection has elements.

Copilot uses AI. Check for mistakes.
}

[McpServerTool(Name = "azsdk_list_typespec_topics"),
Description("Use this tool to list all available TypeSpec and TypeSpec Azure documentation topics with their descriptions.")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When should this be called by LLM? Can you please share sample prompt from user that will invoke this tool?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that this description needs a bit more explanation to make it easier for LLM to decide.

{
logger.LogInformation("Fetching TypeSpec documentation topics");
var response = await docsService.GetTopicsAsync(ct);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: empty line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azsdk-cli Issues related to Azure/azure-sdk-tools::tools/azsdk-cli

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[azsdk tsp mcp] - add support for surfacing TypeSpec docs

3 participants