Skip to content

Commit

Permalink
docs: Document context servers (#21170)
Browse files Browse the repository at this point in the history
This PR adds documentation for context servers.

Release Notes:

- N/A
  • Loading branch information
maxdeviant authored Nov 25, 2024
1 parent b83f104 commit 385c447
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 10 deletions.
9 changes: 0 additions & 9 deletions .cloudflare/docs-proxy/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ export default {
const url = new URL(request.url);
url.hostname = "docs-anw.pages.dev";

// These pages were removed, but may still be served due to Cloudflare's
// [asset retention](https://developers.cloudflare.com/pages/configuration/serving-pages/#asset-retention).
if (
url.pathname === "/docs/assistant/context-servers" ||
url.pathname === "/docs/assistant/model-context-protocol"
) {
return await fetch("https://zed.dev/404");
}

let res = await fetch(url, request);

if (res.status === 404) {
Expand Down
5 changes: 4 additions & 1 deletion docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
- [Inline Assistant](./assistant/inline-assistant.md)
- [Commands](./assistant/commands.md)
- [Prompts](./assistant/prompting.md)
- [Context Servers](./assistant/context-servers.md)
- [Model Context Protocol](./assistant/model-context-protocol.md)

# Extensions

Expand All @@ -51,7 +53,8 @@
- [Developing Extensions](./extensions/developing-extensions.md)
- [Language Extensions](./extensions/languages.md)
- [Theme Extensions](./extensions/themes.md)
- [Slash Commands](./extensions/slash-commands.md)
- [Slash Command Extensions](./extensions/slash-commands.md)
- [Context Server Extensions](./extensions/context-servers.md)

# Language Support

Expand Down
2 changes: 2 additions & 0 deletions docs/src/assistant/assistant.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ This section covers various aspects of the Assistant:
- [Using Commands](./commands.md): Explore slash commands that enhance the Assistant's capabilities and future extensibility.

- [Prompting & Prompt Library](./prompting.md): Learn how to write and save prompts, how to use the Prompt Library, and how to edit prompt templates.

- [Context Servers](./context-servers.md): Learn about context servers that enhance the Assistant's capabilities via the [Model Context Protocol](./model-context-protocol.md).
49 changes: 49 additions & 0 deletions docs/src/assistant/context-servers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Context Servers

Context servers are a mechanism for pulling context into the Assistant from an external source. They are powered by the [Model Context Protocol](./model-context-protocol.md).

Currently Zed supports context servers providing [slash commands](./commands.md) for use in the Assistant.

## Installation

Context servers can be installed via [extensions](../extensions/context-servers.md).

If you don't already have a context server, check out one of these:

- [Postgres Context Server](https://github.com/zed-extensions/postgres-context-server)

## Configuration

Context servers may require some configuration in order to run or to change their behavior.

You can configure each context server using the `context_servers` setting in your `settings.json`:

```json
{
"context_servers": {
"postgres-context-server": {
"settings": {
"database_url": "postgresql://postgres@localhost/my_database"
}
}
}
```

If desired, you may also provide a custom command to execute a context server:

```json
{
"context_servers": {
"my-context-server": {
"command": {
"path": "/path/to/my-context-server",
"args": ["run"],
"env": {}
},
"settings": {
"enable_something": true
}
}
}
}
```
21 changes: 21 additions & 0 deletions docs/src/assistant/model-context-protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Model Context Protocol

Zed uses the [Model Context Protocol](https://modelcontextprotocol.io/) to interact with [context servers](./context-server.md):

> The Model Context Protocol (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools. Whether you're building an AI-powered IDE, enhancing a chat interface, or creating custom AI workflows, MCP provides a standardized way to connect LLMs with the context they need.
Check out the [Anthropic news post](https://www.anthropic.com/news/model-context-protocol) and the [Zed blog post](https://zed.dev/blog/mcp) for an introduction to MCP.

## Try it out

Want to try it for yourself?

The following context servers are available today as Zed extensions:

- [Postgres Context Server](https://github.com/zed-extensions/postgres-context-server)

## Bring your own context server

If there's an existing context server you'd like to bring to Zed, check out the [context server extension docs](../extensions/context-servers.md) for how to make it available as an extension.

If you are interested in building your own context server, check out the [Model Context Protocol docs](https://modelcontextprotocol.io/introduction#get-started-with-mcp) to get started.
39 changes: 39 additions & 0 deletions docs/src/extensions/context-servers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Context Servers

Extensions may provide [context servers](../assistant/context-servers.md) for use in the Assistant.

## Example extension

To see a working example of an extension that provides context servers, check out the [`postgres-context-server` extension](https://github.com/zed-extensions/postgres-context-server).

This extension can be [installed as a dev extension](./developing-extensions.html#developing-an-extension-locally) if you want to try it out for yourself.

## Defining context servers

A given extension may provide one or more context servers. Each context server must be registered in the `extension.toml`:

```toml
[context-servers.my-context-server]
```

Then, in the Rust code for your extension, implement the `context_server_command` method on your extension:

```rust
impl zed::Extension for MyExtension {
fn context_server_command(
&mut self,
context_server_id: &ContextServerId,
project: &zed::Project,
) -> Result<zed::Command> {
Ok(zed::Command {
command: get_path_to_context_server_executable()?,
args: get_args_for_context_server()?,
env: get_env_for_context_server()?,
})
}
}
```

This method should return the command to start up a context server, along with any arguments or environment variables necessary for it to function.

If you need to download the context server from an external source—like GitHub Releases or npm—you can also do this here.
1 change: 1 addition & 0 deletions docs/src/extensions/developing-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Extensions can add the following capabilities to Zed:
- [Languages](./languages.md)
- [Themes](./themes.md)
- [Slash Commands](./slash-commands.md)
- [Context Servers](./context-servers.md)

## Directory Structure of a Zed Extension

Expand Down

0 comments on commit 385c447

Please sign in to comment.