2025-01-27 12:36:12 -05:00
---
title: Building Custom Extensions
2025-11-12 21:05:09 -08:00
description: Create your own custom MCP Server to use as a goose extension
2025-01-27 12:36:12 -05:00
---
2025-08-01 15:42:04 -07:00
import { PanelLeft } from 'lucide-react';
2026-01-07 16:49:52 -08:00
import Tabs from '@theme/Tabs ';
import TabItem from '@theme/TabItem ';
2025-08-01 15:42:04 -07:00
2025-11-12 21:05:09 -08:00
# Building Custom Extensions with goose
2025-01-27 12:36:12 -05:00
2025-11-12 21:05:09 -08:00
goose allows you to extend its functionality by creating your own custom extensions, which are built as MCP servers. These extensions are compatible with goose because it adheres to the [Model Context Protocol (MCP)][mcp-docs]. MCP is an open protocol that standardizes how applications provide context to LLMs. It enables a consistent way to connect LLMs to various data sources and tools, making it ideal for extending functionality in a structured and interoperable way.
2025-01-27 12:36:12 -05:00
2025-11-12 21:05:09 -08:00
In this guide, we build an MCP server using the [Python SDK for MCP][mcp-python]. We’ ll demonstrate how to create an MCP server that reads Wikipedia articles and converts them to Markdown, integrate it as an extension in goose. You can follow a similar process to develop your own custom extensions for goose.
2025-01-27 12:36:12 -05:00
2026-02-11 09:35:24 -05:00
You can check out other example servers in the [MCP servers repository][mcp-servers]. MCP SDKs are also available for other common languages, such as [TypeScript][mcp-typescript] and [Kotlin][mcp-kotlin].
2025-01-27 12:36:12 -05:00
:::info
2026-04-07 01:34:48 -04:00
goose supports Tools, Resources, and Prompts from the [Model Context Protocol ](https://modelcontextprotocol.io/ ). See [`mcp_client.rs` ](https://github.com/aaif-goose/goose/blob/main/crates/goose/src/agents/mcp_client.rs ) for the supported protocol version and client capabilities.
2026-01-07 16:49:52 -08:00
:::
2025-01-27 12:36:12 -05:00
2026-01-07 16:49:52 -08:00
---
2025-01-27 12:36:12 -05:00
2026-01-07 16:49:52 -08:00
## Prerequisites
Before you begin, ensure you have the following installed on your system:
- **Python 3.13 or higher** - Required for the MCP server
- **[uv ](https://docs.astral.sh/uv/ )** - Python package manager used in this tutorial
- **Node.js and npm** - Only required if you want to use the MCP Inspector development tool in [Step 4 ](#step-4-test-your-mcp-server ).
2025-01-27 12:36:12 -05:00
---
## Step 1: Initialize Your Project
The first step is to create a new project using [uv][uv-docs]. We will name our project `mcp-wiki` .
Run the following commands in your terminal to set up a basic structure for your MCP server:
``` bash
2025-08-01 15:42:04 -07:00
uv init --lib mcp-wiki
2025-01-27 12:36:12 -05:00
cd mcp-wiki
mkdir -p src/mcp_wiki
2025-08-01 15:42:04 -07:00
touch src/mcp_wiki/server.py
touch src/mcp_wiki/__main__.py
2025-01-27 12:36:12 -05:00
```
Your project directory structure should look like this:
``` plaintext
.
├── README.md
├── pyproject.toml
2026-01-07 16:49:52 -08:00
└── src
└── mcp_wiki
├── __init__.py # Primary CLI entry point
├── __main__.py # To enable running as a Python module
├── py.typed # Indicates the package supports type hints
└── server.py # Your MCP server code (tool, resources, prompts)
2025-01-27 12:36:12 -05:00
```
---
## Step 2: Write Your MCP Server Code
In this step, we’ ll implement the core functionality of the MCP server. Here is a breakdown of the key components:
1. * * `server.py` **: This file holds the main MCP server code. In this example, we define a single tool to read Wikipedia articles. You can add your own custom tools, resources, and prompts here.
2. * * `__init__.py` **: This is the primary CLI entry point for your MCP server.
3. * * `__main__.py` **: This file allows your MCP server to be executed as a Python module.
Below is the example implementation for the Wikipedia MCP server:
### `server.py`
``` python
import requests
from requests . exceptions import RequestException
from bs4 import BeautifulSoup
from html2text import html2text
2026-01-07 16:49:52 -08:00
from urllib . parse import urlparse
2025-01-27 12:36:12 -05:00
from mcp . server . fastmcp import FastMCP
from mcp . shared . exceptions import McpError
from mcp . types import ErrorData , INTERNAL_ERROR , INVALID_PARAMS
mcp = FastMCP ( " wiki " )
@mcp.tool ( )
def read_wikipedia_article ( url : str ) - > str :
"""
Fetch a Wikipedia article at the provided URL, parse its main content,
convert it to Markdown, and return the resulting text.
Usage:
read_wikipedia_article( " https://en.wikipedia.org/wiki/Python_(programming_language) " )
"""
try :
# Validate input
if not url . startswith ( " http " ) :
raise ValueError ( " URL must start with http or https. " )
2026-01-07 16:49:52 -08:00
# SSRF protection: only allow Wikipedia domains
parsed = urlparse ( url )
hostname = parsed . netloc . lower ( )
2026-06-30 08:58:40 +10:00
2026-01-07 16:49:52 -08:00
# Allow wikipedia.org or *.wikipedia.org subdomains only
if hostname != ' wikipedia.org ' and not hostname . endswith ( ' .wikipedia.org ' ) :
raise ValueError ( f " Only Wikipedia URLs are allowed. Got: { parsed . netloc } " )
# Add User-Agent header to avoid 403 from Wikipedia
headers = {
' User-Agent ' : ' MCP-Wiki/1.0 (Educational purposes; Python requests) '
}
response = requests . get ( url , headers = headers , timeout = 10 )
2025-01-27 12:36:12 -05:00
if response . status_code != 200 :
raise McpError (
ErrorData (
2026-01-07 16:49:52 -08:00
code = INTERNAL_ERROR ,
message = f " Failed to retrieve the article. HTTP status code: { response . status_code } "
2025-01-27 12:36:12 -05:00
)
)
soup = BeautifulSoup ( response . text , " html.parser " )
content_div = soup . find ( " div " , { " id " : " mw-content-text " } )
if not content_div :
raise McpError (
ErrorData (
2026-01-07 16:49:52 -08:00
code = INVALID_PARAMS ,
message = " Could not find the main content on the provided Wikipedia URL. "
2025-01-27 12:36:12 -05:00
)
)
# Convert to Markdown
markdown_text = html2text ( str ( content_div ) )
return markdown_text
except ValueError as e :
2026-01-07 16:49:52 -08:00
raise McpError ( ErrorData ( code = INVALID_PARAMS , message = str ( e ) ) ) from e
2025-01-27 12:36:12 -05:00
except RequestException as e :
2026-01-07 16:49:52 -08:00
raise McpError ( ErrorData ( code = INTERNAL_ERROR , message = f " Request error: { str ( e ) } " ) ) from e
2025-01-27 12:36:12 -05:00
except Exception as e :
2026-01-07 16:49:52 -08:00
raise McpError ( ErrorData ( code = INTERNAL_ERROR , message = f " Unexpected error: { str ( e ) } " ) ) from e
2025-01-27 12:36:12 -05:00
```
### `__init__.py`
``` python
import argparse
from . server import mcp
def main ( ) :
""" MCP Wiki: Read Wikipedia articles and convert them to Markdown. """
parser = argparse . ArgumentParser (
description = " Gives you the ability to read Wikipedia articles and convert them to Markdown. "
)
parser . parse_args ( )
mcp . run ( )
if __name__ == " __main__ " :
main ( )
```
### `__main__.py`
``` python
from mcp_wiki import main
main ( )
```
---
## Step 3: Define Project Configuration
Configure your project using `pyproject.toml` . This configuration defines the CLI script so that the mcp-wiki command is available as a binary. Below is an example configuration:
``` toml
[ project ]
name = "mcp-wiki"
version = "0.1.0"
description = "MCP Server for Wikipedia"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
2026-01-07 16:49:52 -08:00
"beautifulsoup4>=4.14.0" ,
"html2text>=2025.4.15" ,
"mcp[cli]>=1.25.0" ,
2025-01-27 12:36:12 -05:00
"requests>=2.32.3" ,
]
[ project . scripts ]
mcp-wiki = "mcp_wiki:main"
[ build-system ]
requires = [ "hatchling" ]
build-backend = "hatchling.build"
```
---
## Step 4: Test Your MCP Server
2026-01-07 16:49:52 -08:00
Verify that your MCP server is running in the MCP Inspector (a browser-based development tool) or the server CLI.
<Tabs>
<TabItem value="ui" label="In MCP Inspector" default>
:::info
MCP Inspector requires Node.js and npm installed on your computer.
:::
2025-01-27 12:36:12 -05:00
2026-02-11 09:35:24 -05:00
1. Set up the project environment:
2025-01-27 12:36:12 -05:00
```bash
uv sync
` ``
2. Activate your virtual environment:
` ``bash
source .venv/bin/activate
` ``
2026-06-30 08:58:40 +10:00
3. Run your server in development mode:
2025-01-27 12:36:12 -05:00
` ``bash
mcp dev src/mcp_wiki/server.py
` ``
2026-06-30 08:58:40 +10:00
2026-01-07 16:49:52 -08:00
MCP Inspector should open automatically in your browser. On first run, you'll be prompted to install ` @modelcontextprotocol/inspector `.
2025-01-27 12:36:12 -05:00
2026-01-07 16:49:52 -08:00
4. Test the tool:
1. Click ` Connect` to initialize your MCP server
2. On the ` Tools` tab, click ` List Tools` and click the ` read_wikipedia_article` tool
2026-06-30 08:58:40 +10:00
3. Enter ` https://en.wikipedia.org/wiki/Bangladesh` for the URL and click ` Run Tool`
2025-01-27 12:36:12 -05:00
2026-01-07 16:49:52 -08:00
[](../assets/guides/custom-extension-mcp-inspector.png)
2025-01-27 12:36:12 -05:00
2026-01-07 16:49:52 -08:00
</TabItem>
<TabItem value="cli" label="In the CLI">
2026-02-11 09:35:24 -05:00
1. Set up the project environment:
2025-01-27 12:36:12 -05:00
2026-06-30 08:58:40 +10:00
` ``bash
uv sync
` ``
2025-01-27 12:36:12 -05:00
2026-01-07 16:49:52 -08:00
2. Activate your virtual environment:
2025-01-27 12:36:12 -05:00
` ``bash
2026-01-07 16:49:52 -08:00
source .venv/bin/activate
2025-01-27 12:36:12 -05:00
` ``
2026-06-30 08:58:40 +10:00
2026-01-07 16:49:52 -08:00
3. Install your project locally:
2025-01-27 12:36:12 -05:00
` ``bash
2026-01-07 16:49:52 -08:00
uv pip install .
2025-01-27 12:36:12 -05:00
` ``
2026-01-07 16:49:52 -08:00
4. Verify the CLI:
2025-01-27 12:36:12 -05:00
` ``bash
mcp-wiki --help
` ``
You should see output similar to:
` ``plaintext
❯ mcp-wiki --help
usage: mcp-wiki [-h]
Gives you the ability to read Wikipedia articles and convert them to Markdown.
options:
-h, --help show this help message and exit
` ``
2026-06-30 08:58:40 +10:00
2026-01-07 16:49:52 -08:00
</TabItem>
</Tabs>
2025-01-27 12:36:12 -05:00
---
2025-11-12 21:05:09 -08:00
## Step 5: Integrate with goose
2025-01-27 12:36:12 -05:00
2025-11-12 21:05:09 -08:00
To add your MCP server as an extension in goose:
2025-01-27 12:36:12 -05:00
2026-01-07 16:49:52 -08:00
1. Build the extension binary:
` ``bash
uv pip install .
` ``
2. Open goose Desktop and click the <PanelLeft className="inline" size={16} /> button in the top-left to open the sidebar
3. Click ` Extensions` in the sidebar
4. Set the ` Type` to ` STDIO`
5. Provide a name and description for your extension
6. In the ` Command` field, provide the absolute path to your executable:
2026-06-30 08:58:40 +10:00
2025-01-27 12:36:12 -05:00
` ``plaintext
uv run /full/path/to/mcp-wiki/.venv/bin/mcp-wiki
` ``
2025-08-01 15:42:04 -07:00
For example:
2026-06-30 08:58:40 +10:00
2025-08-01 15:42:04 -07:00
` ``plaintext
uv run /Users/smohammed/Development/mcp/mcp-wiki/.venv/bin/mcp-wiki
` ``
2026-01-07 16:49:52 -08:00
:::tip Rebuild binary after changes
To see any changes you make to your MCP server code after integrating with goose, re-run ` uv pip install .` and then restart goose Desktop.
:::
For the purposes of this guide, we'll run the local version. Alternatively, you can publish your package to PyPI. Once published, the server can be run directly using ` uvx`. For example:
2025-01-27 12:36:12 -05:00
` ``
uvx mcp-wiki
` ``
---
2025-11-12 21:05:09 -08:00
## Step 6: Use Your Extension in goose
2025-01-27 12:36:12 -05:00
2025-11-12 21:05:09 -08:00
Once integrated, you can start using your extension in goose. Open the goose chat interface and call your tool as needed.
2025-01-27 12:36:12 -05:00
2025-11-12 21:05:09 -08:00
You can verify that goose has picked up the tools from your custom extension by asking it "what tools do you have?"
2025-01-27 12:36:12 -05:00
2025-11-12 21:05:09 -08:00

2025-01-27 12:36:12 -05:00
Then, you can try asking questions that require using the extension you added.
2025-11-12 21:05:09 -08:00

2025-01-27 12:36:12 -05:00
2025-11-12 21:05:09 -08:00
🎉 **Congratulations!** You’ ve successfully built and integrated a custom MCP server with goose.
2025-01-27 12:36:12 -05:00
2025-11-12 21:05:09 -08:00
---
## Advanced Features for MCP Extensions
goose supports advanced MCP features that can enhance your extensions.
### MCP Sampling: AI-Powered Tools
**[MCP Sampling](/docs/guides/mcp-sampling)** allows your MCP servers to request AI completions from goose's LLM, transforming simple tools into intelligent agents.
**Key Benefits:**
2026-06-30 08:58:40 +10:00
2025-11-12 21:05:09 -08:00
- Your MCP server doesn't need its own OpenAI/Anthropic API key
- Tools can analyze data, provide explanations, and make intelligent decisions
- Enhanced user experience with smarter, more contextual responses
- Secure by design: requests are isolated and attributed automatically
**Getting Started:**
2026-06-30 08:58:40 +10:00
2025-11-12 21:05:09 -08:00
- Use the ` sampling/createMessage` method in your MCP server to request AI assistance
2026-04-07 01:34:48 -04:00
- [goose's implementation ](https://github.com/aaif-goose/goose/blob/main/crates/goose/src/agents/mcp_client.rs ) currently supports text and image content types
2025-11-12 21:05:09 -08:00
- goose automatically advertises sampling capability to all MCP servers
**Use Cases: ** Document summarization, smart search filtering, code analysis, data insights
**Learn More: ** See the [MCP Specification ](https://modelcontextprotocol.io/specification/draft/client/sampling ) for technical details.
2026-01-07 18:06:31 -05:00
### MCP Apps: Interactive Extensions
2025-11-12 21:05:09 -08:00
2026-01-07 18:06:31 -05:00
* * [MCP Apps ](/docs/tutorials/building-mcp-apps )** enable rich, interactive user interfaces instead of text-only responses.
2025-11-12 21:05:09 -08:00
**Key Benefits: **
2026-06-30 08:58:40 +10:00
2026-01-07 18:06:31 -05:00
- Return interactive UI components from your MCP server tools
- Components render securely in isolated sandboxes within goose Desktop
- Real-time user interactions trigger callbacks to your server
2025-11-12 21:05:09 -08:00
2026-01-07 18:06:31 -05:00
**Use Cases: ** Interactive forms, data visualizations, booking interfaces, configuration wizards
2025-11-12 21:05:09 -08:00
2026-01-07 18:06:31 -05:00
**Learn More: ** [Building MCP Apps Tutorial ](/docs/tutorials/building-mcp-apps )
2025-01-27 12:36:12 -05:00
[mcp-docs]: https://modelcontextprotocol.io/
[mcp-python]: https://github.com/modelcontextprotocol/python-sdk
[mcp-typescript]: https://github.com/modelcontextprotocol/typescript-sdk
[mcp-kotlin]: https://github.com/modelcontextprotocol/kotlin-sdk
[mcp-servers]: https://github.com/modelcontextprotocol/servers
[uv-docs]: https://docs.astral.sh/uv/getting-started/