# Sourcegraph

> Search and navigate code across all your repositories - code search, file content, repo info, commits, and symbols - with Sourcegraph's GraphQL API.

Lets an agent search and read code across every repository connected to your Sourcegraph instance: run code searches with the full search syntax, fetch file content, look up repository metadata, walk commit history, and find symbols. Works against Sourcegraph Cloud (sourcegraph.com) or your own self-hosted instance.

## What it can do

| Method | What it does |
| --- | --- |
| `sourcegraph_search` | Search code across all repositories with the full Sourcegraph search syntax; supports literal, regexp, structural, and keyword pattern types. |
| `sourcegraph_get_file_content` | Get the content of a single file at a revision. |
| `sourcegraph_repository` | Get repository info: url, description, language, stars, default branch, and flags. |
| `sourcegraph_commits` | List commit / blame history for a repo or a file path. |
| `sourcegraph_find_symbols` | Find symbols (functions, classes, etc.) in a repository, with their source location. |
| `sourcegraph_graphql` | Generic passthrough: run any Sourcegraph GraphQL query or mutation for full API coverage. |

## How to get your token

Sourcegraph authenticates API calls with an access token sent as `Authorization: token <TOKEN>`.

1. Sign in to your Sourcegraph instance (or [sourcegraph.com](https://sourcegraph.com)).
2. Open **Settings -> Access tokens** ([create a token](https://sourcegraph.com/user/settings/tokens)).
3. Click **Generate new token**, give it a name, and copy the value - it is shown once.
4. Paste it into FlyMyAI.
5. If you run a self-hosted Sourcegraph, also paste your instance URL (e.g. `https://sourcegraph.example.com`).

## Fields to fill

| FlyMyAI field | Where it comes from |
| --- | --- |
| `SOURCEGRAPH_TOKEN` | Sourcegraph -> Settings -> Access tokens |
| `SOURCEGRAPH_URL` | Optional - your self-hosted instance base URL; defaults to `https://sourcegraph.com` |

## Troubleshooting

- **`401 Unauthorized`** - the token is wrong, revoked, or for a different instance. Generate a new one and re-paste it.
- **No results from `sourcegraph_search`** - check the query syntax and `repo:` filter. The repository must be indexed by your Sourcegraph instance.
- **`repository not found`** - use the canonical repo name (e.g. `github.com/org/repo`, no protocol) and make sure the repo is added to Sourcegraph.
- **Self-hosted instance unreachable** - confirm `SOURCEGRAPH_URL` is the correct base URL and the instance is reachable from the internet.

## Links

- [Sourcegraph GraphQL API reference](https://sourcegraph.com/docs/api/graphql)
- [Access tokens](https://sourcegraph.com/user/settings/tokens)
