foxy-contexts
Foxy Contexts: Golang library for building MCP servers, simplifying AI model integration with tools, resources, and prompts.

foxy-contexts Solution Overview
Foxy Contexts is a Golang library designed to simplify the creation of MCP-compliant context servers. It empowers developers to build robust servers using a declarative approach, defining tools, resources, and prompts that seamlessly integrate with AI models. By leveraging Uber's FX App for dependency injection, Foxy Contexts promotes code reusability and simplifies the management of shared components like database connections and clients.
This library streamlines the process of connecting AI models to external data and services. Developers can easily define the logic for accessing and manipulating data, while the dependency injection mechanism ensures that components are properly configured and managed. Foxy Contexts supports standard input/output and SSE transport, with plans to include streamable HTTP. Key features include lifecycle management, static and dynamic resource provision, and a functional testing package. Foxy Contexts enables developers to focus on building valuable AI integrations rather than grappling with complex infrastructure.
foxy-contexts Key Capabilities
Declarative Server Construction
Foxy Contexts simplifies MCP server development by employing a declarative approach in Golang. Developers define tools, resources, and prompts, then register them with the app.Builder
. This builder leverages Uber's fx App for dependency injection, enabling modular design and reusability. This approach contrasts with imperative coding, where developers manually manage the server's lifecycle and dependencies. By focusing on what the server should do rather than how to do it, Foxy Contexts reduces boilerplate code and improves maintainability.
For example, a developer can define a tool that fetches real-time stock prices by declaring its input schema, description, and the function to execute when called. The app.Builder
then automatically handles the tool's registration and integration into the MCP server. This declarative style promotes code clarity and reduces the risk of errors.
Dependency Injection for Reusability
Foxy Contexts leverages dependency injection (DI) via Uber's fx App to promote code reusability and modularity. DI allows developers to inject shared components, such as database connections or API clients, into tools, resources, and prompts. This eliminates the need to create multiple instances of these components, reducing resource consumption and improving performance. Furthermore, DI simplifies testing by allowing developers to mock dependencies and isolate components.
Consider a scenario where multiple tools need to access a shared database. Instead of each tool creating its own database connection, Foxy Contexts allows developers to inject a single database connection instance into all the tools. This ensures that all tools use the same connection, reducing the load on the database and improving consistency. This approach also makes it easier to update the database connection configuration, as it only needs to be changed in one place.
Streamable HTTP Transport
Foxy Contexts supports Streamable HTTP Transport (beta), enabling efficient data transfer between the MCP server and clients. This transport mechanism allows for sending large amounts of data in chunks, reducing memory consumption and improving responsiveness. Unlike traditional HTTP, which requires the entire response to be buffered before sending, Streamable HTTP Transport allows data to be sent as it becomes available.
For instance, an AI model might request a large dataset from a resource. With Streamable HTTP Transport, the resource can send the data in chunks, allowing the model to start processing the data before the entire dataset has been transferred. This reduces latency and improves the overall performance of the AI model. The implementation uses HTTP/SSE (Server-Sent Events) to push data from the server to the client, providing a real-time data streaming experience.
Functional Testing with foxytest
Foxy Contexts includes a foxytest
package that simplifies functional testing of MCP servers. This package provides tools for creating test clients, sending requests to the server, and verifying the responses. By using foxytest
, developers can ensure that their MCP servers are working correctly and that they meet the required specifications. The package integrates seamlessly with Golang's testing framework, making it easy to write and run tests.
For example, a developer can use foxytest
to verify that a tool returns the correct output for a given input. The developer can create a test client, send a request to the tool with the input, and then assert that the response matches the expected output. This helps to catch errors early in the development process and ensures that the MCP server is functioning as intended. The dependency injection feature further enhances testability by allowing developers to easily mock dependencies during testing.