AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How Do Software Engineers Configure OpenCtx in Sourcegraph Cody to Inject External Docs and MCP Servers into AI Chat?

Carmen Gracia Santos · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Even the most capable AI coding assistant is only as good as the context feeding its prompt window. When working within a mature monorepo or standard microservice, Sourcegraph Cody does an admirable job indexing local source trees, tracing symbol definitions, and navigating multi-repository dependencies. But backend and full-stack software development rarely exists in a vacuum.

In real-world engineering, you are almost never writing code against static codebases alone. You are integrating fast-moving third-party cloud SDKs, internal private microservice endpoints documented in remote OpenAPI specs, evolving schema migrations in staging databases, and live tickets tracked in issue trackers. Left to its default context, an LLM defaults to the stale patterns frozen into its pre-training cutoff date. The result is familiar to every backend engineer: the model hallucinates deprecated SDK methods, invents non-existent function arguments, or generates database queries referencing discarded column names.

The instinctive workaround—alt-tabbing to a browser window, copying raw HTML or markdown from API documentation, and pasting clumsy chunks into the IDE chat sidebar—breaks developer flow. Sourcegraph created OpenCtx to eliminate this friction.

365Finds has evaluated context orchestration across modern developer tools, and our verdict is straightforward: Sourcegraph Cody’s OpenCtx architecture is one of the most flexible open context pipelines available in the IDE ecosystem, especially when paired with the Model Context Protocol (MCP). However, teams often stumble because the configuration model spans multiple configuration levels and behaves differently across IDE clients.

Here is how software engineers and platform teams configure OpenCtx inside Sourcegraph Cody to bridge live documentation and MCP servers directly into your daily coding workflow.


The OpenCtx Context Architecture in Sourcegraph Cody

To understand why OpenCtx matters, you need to understand how Cody assembles a prompt. When you submit a prompt in Cody chat, Cody constructs a composite context payload consisting of:

  1. User input and intent.
  2. Local workspace context (active editor selection, nearby code chunks, symbol graph references, or Sourcegraph remote search hits).
  3. External context providers dynamically invoked through the OpenCtx protocol.

OpenCtx is an open standard designed to decouple context sources from the IDE itself. Instead of waiting for Sourcegraph or plugin developers to build bespoke integrations for every documentation site, issue tracker, and database engine, OpenCtx defines a uniform protocol. Any context provider—whether hosted as an npm module, executed as a local Node.js process, or bridging into Anthropic’s Model Context Protocol (MCP)—can stream real-time contextual items directly into Cody’s @-mention interface.

IDE Parity: VS Code vs. JetBrains

Before writing configuration files, engineering teams must recognize an important platform distinction:

Feature / CapabilityVisual Studio CodeJetBrains IDEs (IntelliJ, PyCharm, GoLand)Visual Studio
Local File & Symbol @-mentionsFull SupportFiles supported; Symbols restrictedFull Support
Web URLs FetchingFull SupportSupported nativelyFull Support
OpenCtx Custom Providers (openctx.providers)Full SupportNot yet supported for arbitrary OpenCtxFull Support
Multi-Repository Context SearchSupportedSupportedSupported

At 365Finds, we believe it is essential to be completely transparent here: OpenCtx custom provider orchestration is first-class in VS Code and Visual Studio. If your team works primarily in JetBrains IDEs, you can still leverage Cody's native Web URL fetching and multi-repo search, but custom openctx.providers blocks are currently exclusive to the VS Code/Visual Studio extension architectures. Do not spend hours debugging provider hooks on JetBrains until Sourcegraph releases full parity for OpenCtx on that platform.


Step 1: Configuring openctx.providers in settings.json

OpenCtx configuration lives under the openctx.providers JSON object. You can declare this configuration at two distinct levels:

Each key in the openctx.providers block represents the provider identifier—typically an HTTPS URI pointing to an npm package or an internal service URL—and the value contains either true (to enable with defaults) or a configuration object tailored to that provider.

{
  "openctx.providers": {
    "https://openctx.org/npm/@openctx/provider-web": true,
    "https://openctx.org/npm/@openctx/provider-devdocs": {
      "urls": [
        "https://devdocs.io/go/",
        "https://devdocs.io/aws~javascript/"
      ]
    }
  }
}

When VS Code loads Cody with this block, Cody boots the respective OpenCtx runtime in background worker threads, downloads the required provider bundles, and registers them into the context registry.


Step 2: Injecting Live Documentation via @openctx/provider-web

When working with rapidly evolving third-party SDKs—such as AWS SDK for JavaScript v3, Stripe API changes, or Kubernetes operator APIs—the simplest way to eradicate hallucinations is mounting @openctx/provider-web.

The Configuration

Add the official web context provider to your settings.json:

{
  "openctx.providers": {
    "https://openctx.org/npm/@openctx/provider-web": true
  }
}

How It Operates Under the Hood

When this provider is active, Cody gains the ability to parse arbitrary web URLs, strip extraneous DOM noise (navigation bars, footers, advertisements), and convert the core technical documentation into token-optimized markdown representation.

Rather than you reading documentation, summarizing it, and pasting it into the chat prompt, Cody pulls the live web page directly into its immediate context window right alongside your open editor buffers.


Step 3: Bridging Model Context Protocol (MCP) Servers via OpenCtx

The true force multiplier for enterprise backend engineering is connecting Cody to Anthropic's Model Context Protocol (MCP). MCP provides a standardized way for AI tools to query local filesystems, query staging databases, inspect Jira/Linear issues, or read private internal service catalogs.

Sourcegraph supports bridging MCP servers into Cody through @openctx/provider-modelcontextprotocol.

Connecting a Database Schema MCP Server

Consider a common scenario: a backend developer is writing complex SQL queries or ORM entities in Go or Node.js. If the developer asks Cody to generate an analytical query, Cody has to guess the column types, foreign key relations, and indexes.

By running a local PostgreSQL MCP server, Cody can read schema metadata directly from your development database.

Here is the configuration block in settings.json:

{
  "openctx.providers": {
    "https://openctx.org/npm/@openctx/provider-modelcontextprotocol": {
      "nodeCommand": "node",
      "mcp.provider.uri": "file:///Users/developer/mcp-servers/postgres-server/build/index.js",
      "mcp.provider.args": [
        "--connection-string",
        "postgresql://dev_user:dev_pass@localhost:5432/orders_db"
      ]
    }
  }
}

Key Parameters:

Once configured, reload the VS Code window (Developer: Reload Window in the Command Palette) to ensure the provider subprocess initializes cleanly.


Step 4: Summoning Context Dynamically via @-mentions in Cody Chat

With your providers registered, how do you actually invoke external context during coding? You do not need complex slash commands. Sourcegraph Cody integrates all OpenCtx and MCP providers into the unified @ context menu.

The Interactive Workflow

  1. Open the Cody Chat panel in the VS Code sidebar (Ctrl+Alt+A or Cmd+Shift+A).
  2. In the chat input box, type @.
  3. Cody opens the dynamic context picker. Alongside Files and Symbols, you will see dedicated entries for your enabled OpenCtx providers:
    • Web URLs: Mention specific technical documentation links.
    • DevDocs: Search curated language documentation directly from the IDE.
    • Model Context Protocol Resources: Access tables, schemas, or live tool endpoints exposed by your MCP server.

Real-World Prompt Examples

Scenario A: Writing Cloud Code Against Fresh Documentation

@https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/index.html
Refactor our legacy S3 upload service in services/s3.ts to use the AWS SDK v3 PutObjectCommand with a streaming multipart upload. Use the exact types and error handling shown in the documentation.

Cody fetches the URL payload via @openctx/provider-web, inspects the current services/s3.ts buffer, and writes the code using modern v3 syntax without confusing it with deprecated v2 callback patterns.

Scenario B: Authoring Repository Migrations Against Live Database Schemas

@mcp://postgres/orders_db/schema
Write a new Go database repository method in internal/repo/orders.go to fetch customer order histories grouped by quarterly spend. Ensure you match the exact column names, UUID types, and foreign key relations from our orders and line_items tables.

Cody queries the PostgreSQL MCP server through OpenCtx, verifies the actual database constraints, and outputs SQL and Go structs that match your database down to the exact field naming convention.


Step 5: Team Sharing via .vscode/settings.json and Secret Hygiene

A recurring frustration in software engineering teams is configuration drift: one senior engineer figures out how to supercharge their IDE with AI context, while the rest of the team continues struggling with manual copy-pasting.

Sourcegraph Cody enables entire teams to share context configurations by committing .vscode/settings.json to the project repository.

your-project/
├── .vscode/
│   ├── settings.json         <-- Shared OpenCtx providers (Web docs, DevDocs, public MCPs)
│   └── settings.local.json   <-- (Gitignored) Personal credentials and local paths
├── src/
├── package.json
└── README.md

Critical Security Rule: Never Commit Plaintext Credentials

365Finds strongly cautions against hardcoding authentication credentials inside .vscode/settings.json:

Context Budgeting: Preventing Token Flooding

Context injection is powerful, but LLM token windows are finite. If you attach five massive 50-page web specifications to a single chat prompt, you will consume tens of thousands of tokens before Cody even begins analyzing your local code. This degrades response generation speed and risks truncating relevant workspace context.

Our recommended team practice:

  1. Targeted URLs: Point @openctx/provider-web to specific API reference pages rather than documentation homepage roots.
  2. Prune MCP outputs: Ensure your custom MCP servers implement sensible pagination or query filtering rather than returning raw multi-megabyte database dumps.
  3. Inspect Cody Context Tokens: Check the context indicator at the top of Cody’s chat box to monitor how many tokens were absorbed by attached providers before firing the prompt.

References