# Sourcegraph — how to use (mcp.ai)

Connect your Sourcegraph account and use 8 tools for developer tools straight from your AI agent. Connect with your own API key. Sourcegraph is a code intelligence platform that enables developers to search, understand, and manage code across large codebases.

## Option A — via MCP (recommended)
Remote MCP endpoint (HTTP, streamable): `https://api.mcp.ai/p_sourcegraph?ms=1787295660000`
Add it as a custom/remote MCP connector in your client (Claude, Cursor, VS Code…), then authenticate when prompted. Once connected, ask the agent to use the server's tools (e.g. `sourcegraph_check_site_settings_edit_permission`).

## Option B — via direct REST API
Base URL: `https://api.mcp.ai/api/sourcegraph`
Auth: `Authorization: Bearer sk_live_…` — create a workspace API key at https://mcp.ai/settings/api-keys
Discover endpoints: `GET https://api.mcp.ai/api/sourcegraph/_endpoints`

### Endpoints
- `POST https://api.mcp.ai/api/sourcegraph/check/site/settings/edit/permission` — Tool to check whether site settings can be edited through the API. Use when you need to confirm the API allows site settings edits before attempting configuration changes.
- `POST https://api.mcp.ai/api/sourcegraph/compare/commits` — Tool to compare two commits in a repository and retrieve their file diffs. Use after confirming the repository name and commit SHAs to inspect differences.
  - body: { base: string, head: string, repo: string }
- `POST https://api.mcp.ai/api/sourcegraph/get/commit/details` — Get detailed information about a specific commit in a repository.
  - body: { rev: string, repo: string }
- `POST https://api.mcp.ai/api/sourcegraph/get/current/user` — Tool to retrieve information about the currently authenticated user. Use when needing confirmation of identity via Sourcegraph GraphQL API.
- `POST https://api.mcp.ai/api/sourcegraph/get/file/contents` — Tool to fetch the contents of a specified file on the default branch. Use when you need raw file text without cloning the repo or using a slower code-host API.
  - body: { file_path: string, repo_name: string }
- `POST https://api.mcp.ai/api/sourcegraph/list/repositories` — Tool to list repositories on the Sourcegraph instance. Use when you need to paginate through all available repositories.
  - body: { after?: string, first: integer }
- `POST https://api.mcp.ai/api/sourcegraph/list/repository/files` — Tool to list all files and directories in a repository path. Use when you need to enumerate files in a repository without cloning.
  - body: { rev?: string, path?: string, recursive?: boolean, repo_name: string }
- `POST https://api.mcp.ai/api/sourcegraph/list/repository/languages` — Tool to list languages used in a repository. Use when you need to determine the primary and all languages of a given repository; call after you have the repository name.
  - body: { repoName: string }

## Example prompts
- "What can I do in Sourcegraph?"
- "Show me a summary of my Sourcegraph account"

## More
- Page: https://mcp.ai/sourcegraph
- Agent spec (llms.txt): https://mcp.ai/sourcegraph/llms.txt
- Postman collection: https://mcp.ai/sourcegraph/postman.json
