Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

Create MCP endpoint to wrap GitHub Docs API

Summary

This PR adds a new MCP endpoint that wraps the GitHub Docs API to allow searching GitHub's official documentation at docs.github.com.

Changes Made

New Tool: search_github_docs

  • Searches docs.github.com for help articles, guides, and API documentation
  • Supports query parameters for:
    • query (required): Search query string
    • version (optional): GitHub version (dotcom, ghec, or GHES version like 3.12)
    • language (optional): Language code (en, es, ja, pt, zh, ru, fr, ko, de)
    • max_results (optional): Maximum results to return (1-100, default 10)
  • Returns formatted search results with titles, URLs, breadcrumbs, and content snippets

New Toolset: github_docs

  • Added to the list of available toolsets
  • Read-only toolset (no write operations)
  • Can be enabled with --toolsets=github_docs

Tests

  • Added comprehensive unit tests for the new tool
  • Tests cover parameter validation, error cases, and response parsing
  • All existing tests continue to pass

Documentation

  • README.md automatically updated with new toolset information
  • Tool appears in help output and available toolsets list
  • Fixed capitalization to match GitHub branding (GitHub Docs)
  • Updated doc generator to properly format "github_docs" toolset name

Linting

  • Fixed all linting errors:
    • Added error check for JSON encoding in tests
    • Added nosec comment for HTTP.Get with proper justification
    • Renamed unused context parameter to _
    • Renamed unused request parameter in test to _

Implementation Details

  • Uses the GitHub Docs search API at https://docs.github.com/api/search/v1
  • No authentication required (public API)
  • Supports multiple languages and GitHub versions
  • Default values: version=dotcom, language=en, max_results=10
Original prompt

create an MCP endpoint that wraps the GitHub Docs API


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@colindembovsky
Copy link

@crwaters16 from SFO

Copilot AI changed the title [WIP] Create MCP endpoint for GitHub Docs API Add GitHub Docs search MCP endpoint Oct 30, 2025
Copilot AI requested a review from colindembovsky October 30, 2025 16:16
Copilot finished work on behalf of colindembovsky October 30, 2025 16:16
@crwaters16
Copy link

@sarahs - did Copilot pull in the right docs API to do this?

@colindembovsky
Copy link

@copilot make sure the API is using the correct endpoints like this:

Examples & reference

General REST search overview and guidance: https://docs.github.com/en/rest/search/search
Text-match metadata: https://docs.github.com/en/rest/search/search#text-match-metadata
Search topics example and parameters: https://docs.github.com/en/rest/search/search#search-topics

Copy link
Contributor Author

Copilot AI commented Oct 30, 2025

@copilot make sure the API is using the correct endpoints like this:

Examples & reference...

I implemented a tool that searches GitHub's documentation content at docs.github.com using their search API endpoint (https://docs.github.com/api/search/v1). This is different from the GitHub REST API search endpoints you linked (which search repositories, code, issues, topics, etc.).

The current implementation searches the actual documentation articles/guides (similar to the remote-only github_support_docs_search tool mentioned in the README).

Did you want me to:

  1. Keep the current docs content search implementation, or
  2. Change it to use the GitHub REST API search endpoints (for searching topics, repositories, etc.)?

The REST API endpoints you referenced are already implemented in this codebase as search_repositories, search_code, search_issues, etc.

Copilot finished work on behalf of colindembovsky October 30, 2025 16:28
@colindembovsky
Copy link

@copilot the doc check is failing:

The generated documentation differs from what's committed.
Please run the following command to update the documentation:

go run ./cmd/github-mcp-server generate-docs

Then commit the changes.

Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot the doc check is failing:

The generated documentation differs from what's committed.
...

Fixed in commit 93a13ee. Added a case in the formatToolsetName function to properly format "github_docs" as "GitHub Docs" with correct capitalization. The documentation now generates correctly.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • docs.github.com
    • Triggering command: /tmp/go-build2752504925/b001/github.test -test.testlogfile=/tmp/go-build2752504925/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.run=TestSearchGitHubDocs (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of colindembovsky October 31, 2025 17:58
@colindembovsky
Copy link

@copilot the go_lint command is failing in the build:

Error: pkg/github/docs_test.go:130:31: Error return value of (*encoding/json.Encoder).Encode is not checked (errcheck)
json.NewEncoder(w).Encode(tc.serverResponse)
^
Error: pkg/github/docs.go:107:17: G107: Potential HTTP request made with variable url (gosec)
resp, err := http.Get(searchURL)
^
Error: pkg/github/docs.go:59:8: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
^
Error: pkg/github/docs_test.go:127:82: unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
mockServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
^
4 issues:

  • errcheck: 1
  • gosec: 1
  • revive: 2

Please fix

Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot the go_lint command is failing in the build:

Error: pkg/github/docs_test.go:130:31: Error return value of (*encoding/json.Encoder).Encode is not checked (errcheck)
...

Fixed in commit 8658c22. All linting errors resolved:

  • Added error check for json.NewEncoder(w).Encode() in test
  • Added #nosec G107 comment for HTTP.Get with justification
  • Renamed unused ctx parameter to _
  • Renamed unused r parameter to _ in test

The code now passes all lint checks with 0 issues.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • docs.github.com
    • Triggering command: /tmp/go-build417247941/b001/github.test -test.testlogfile=/tmp/go-build417247941/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.run=TestSearchGitHubDocs -test.v=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of colindembovsky October 31, 2025 18:39
@colindembovsky colindembovsky marked this pull request as ready for review October 31, 2025 20:30
@colindembovsky colindembovsky requested a review from a team as a code owner October 31, 2025 20:30
Copilot AI review requested due to automatic review settings October 31, 2025 20:30
Copy link
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 a new MCP endpoint that wraps the GitHub Docs API, enabling users to search GitHub's official documentation at docs.github.com directly through the MCP server.

Key Changes:

  • Adds search_github_docs tool with support for query, version, language, and max_results parameters
  • Creates new github_docs toolset (read-only) with comprehensive test coverage
  • Updates documentation and toolset formatting to properly display "GitHub Docs"

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/github/docs.go Implements the search_github_docs tool with API integration and parameter validation
pkg/github/docs_test.go Adds comprehensive unit tests for the new docs search functionality
pkg/github/tools.go Registers the new github_docs toolset and integrates it into the toolset group
pkg/github/instructions.go Adds usage instructions for the github_docs toolset
pkg/github/instructions_test.go Adds test coverage for github_docs toolset instructions
pkg/github/toolsnaps/search_github_docs.snap Snapshot file for tool definition validation
cmd/github-mcp-server/generate_docs.go Adds formatting rule to display "GitHub Docs" instead of "Github Docs"
docs/remote-server.md Documents the new github_docs toolset with installation links
README.md Updates toolset list and adds detailed tool documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +107 to +108
// #nosec G107 - URL is constructed from validated parameters with proper escaping
resp, err := http.Get(searchURL)
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

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

The nosec comment justifies URL construction with proper escaping, but the URL concatenation in line 99-104 uses url.QueryEscape which is intended for query parameter values. For the entire URL construction, consider using url.Values with Encode() or ensure each component is escaped with the appropriate function (e.g., url.PathEscape for path segments if needed).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants