Skip to content
Back to search

foxy-contexts

Foxy contexts is a library for building context servers supporting Model Context Protocol

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/strowk--foxy-contexts/badge.svg)](/listings/strowk--foxy-contexts)

HTML

<a href="/listings/strowk--foxy-contexts"><img src="/api/listings/strowk--foxy-contexts/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 179 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. <h1 align="center">
  2. <img alt="main logo" src="./docs/content/assets/logo.png" width="150"/>
  3. <br/>
  4. Foxy Contexts
  5. </h1>
  6. <!-- --8<-- [start:content] -->
  7. <h4 align="center">Build MCP Servers Declaratively in Golang</h4>
  8. <p align="center">
  9. <a href="https://pkg.go.dev/github.com/strowk/foxy-contexts"><img src="https://pkg.go.dev/badge/github.com/strowk/foxy-contexts.svg" alt="Go Reference"></a>
  10. <a href="https://goreportcard.com/report/github.com/strowk/foxy-contexts"><img src="https://goreportcard.com/badge/github.com/strowk/foxy-contexts" alt="Go Reference"></a>
  11. <a href="https://github.com/strowk/foxy-contexts/actions/workflows/test.yaml"><img src="https://github.com/strowk/foxy-contexts/actions/workflows/test.yaml/badge.svg"/></a>
  12. <a href="https://github.com/strowk/foxy-contexts/actions/workflows/golangci-lint.yaml"><img src="https://github.com/strowk/foxy-contexts/actions/workflows/golangci-lint.yaml/badge.svg"/></a>
  13. </p>
  14. <p align="center">
  15. <a href="#features">Features</a> 🦊
  16. <a href="#tool-example">Tool Example</a> 🦊
  17. <a href="https://foxy-contexts.str4.io">Docs</a> 🦊
  18. <a href="https://github.com/strowk/foxy-contexts">Sources</a>
  19. </p>
  20. Foxy contexts is a Golang library for building context servers supporting [Model Context Protocol](https://modelcontextprotocol.io/).
  21. This library only supports server side of the protocol. Using it you can build context servers using declarative approach, by defining [tools](https://modelcontextprotocol.io/docs/concepts/tools), [resources](https://modelcontextprotocol.io/docs/concepts/resources) and [prompts](https://modelcontextprotocol.io/docs/concepts/prompts) and then registering them with your app.Builder, which is using [uber's fx](https://github.com/uber-go/fx) App under the hood and you can inject into its container as well.
  22. With this approach you can easily colocate call/read/get logic and definitions of your tools/resources/prompts in a way that every tool/resource/prompt is placed in a separate place, while Dependency Injection allows you to reuse shared parts like clients, database connections, etc.
  23. ## Features
  24. Here is list of features that are implemented and planned:
  25. - [x] Base (lifecycle/ping)
  26. - [ ] Progress (planned)
  27. - [x] Transports
  28. - [x] Stdio Transport
  29. - [x] SSE Transport
  30. - [x] Streamable HTTP Transport (beta)
  31. - [x] Tools
  32. - [x] Package toolinput helps define tools input schema and validate arriving input
  33. - [ ] Resources
  34. - [x] Resources - static
  35. - [x] Resources - dynamic via Resource Providers
  36. - [ ] Resources - dynamic via Resource Templates (planned)
  37. - [ ] Resource Templates completion (planned)
  38. - [ ] Resource subscriptions
  39. - [x] Prompts
  40. - [x] Prompts Completion
  41. - [x] Functional Testing package foxytest
  42. - [x] Simple building of your MCP server with the power of Dependency Injection
  43. - [ ] Logging via MCP (planned)
  44. - [ ] Sampling (planned)
  45. - [ ] Roots (planned)
  46. - [ ] Pagination (planned)
  47. - [ ] Notifications list_changed (planned)
  48. - [x] Testing - functional tests with foxytest package
  49. Check [docs](https://foxy-contexts.str4.io/) and [examples](https://github.com/strowk/foxy-contexts/tree/main/examples) to know more.
  50. ## Tool Example
  51. For example try following
  52. ```bash
  53. git clone https://github.com/strowk/foxy-contexts
  54. cd foxy-contexts/examples/list_current_dir_files_tool
  55. npx @modelcontextprotocol/inspector go run main.go
  56. ```
  57. , then once inspector is started in browser open http://localhost:6274 and try to use list-current-dir-files.
  58. Here's the code of that example from [examples/list_current_dir_files_tool/main.go](https://github.com/strowk/foxy-contexts/blob/main/examples/list_current_dir_files_tool/main.go) (in real world application you would probably want to split it into multiple files):
  59. ```go
  60. package main
  61. import (
  62. "fmt"
  63. "os"
  64. "github.com/strowk/foxy-contexts/pkg/app"
  65. "github.com/strowk/foxy-contexts/pkg/fxctx"
  66. "github.com/strowk/foxy-contexts/pkg/mcp"
  67. "github.com/strowk/foxy-contexts/pkg/stdio"
  68. "go.uber.org/fx"
  69. "go.uber.org/fx/fxevent"
  70. "go.uber.org/zap"
  71. )
  72. // This example defines list-current-dir-files tool for MCP server, that prints files in the current directory
  73. // , run it with:
  74. // npx @modelcontextprotocol/inspector go run main.go
  75. // , then in browser open http://localhost:6274
  76. // , then click Connect
  77. // , then click List Tools
  78. // , then click list-current-dir-files
  79. // NewListCurrentDirFilesTool defines a tool that lists files in the current directory
  80. func NewListCurrentDirFilesTool() fxctx.Tool {
  81. return fxctx.NewTool(
  82. // This information about the tool would be used when it is listed:
  83. &mcp.Tool{
  84. Name: "list-current-dir-files",
  85. Description: Ptr("Lists files in the current directory"),
  86. InputSchema: mcp.ToolInputSchema{
  87. Type: "object",
  88. Properties: map[string]map[string]interface{}{},
  89. Required: []string{},
  90. },
  91. },
  92. // This is the callback that would be executed when the tool is called:
  93. func(_ context.Context, args map[string]interface{}) *mcp.CallToolResult {
  94. files, err := os.ReadDir(".")
  95. if err != nil {
  96. return &mcp.CallToolResult{
  97. IsError: Ptr(true),
  98. Meta: map[string]interface{}{},
  99. Content: []interface{}{
  100. mcp.TextContent{
  101. Type: "text",
  102. Text: fmt.Sprintf("failed to read dir: %v", err),
  103. },
  104. },
  105. }
  106. }
  107. var contents []interface{} = make([]interface{}, len(files))
  108. for i, f := range files {
  109. contents[i] = mcp.TextContent{
  110. Type: "text",
  111. Text: f.Name(),
  112. }
  113. }
  114. return &mcp.CallToolResult{
  115. Meta: map[string]interface{}{},
  116. Content: contents,
  117. IsError: Ptr(false),
  118. }
  119. },
  120. )
  121. }
  122. func main() {
  123. app.
  124. NewBuilder().
  125. // adding the tool to the app
  126. WithTool(NewListCurrentDirFilesTool).
  127. // setting up server
  128. WithName("list-current-dir-files").
  129. WithVersion("0.0.1").
  130. WithTransport(stdio.NewTransport()).
  131. // Configuring fx logging to only show errors
  132. WithFxOptions(fx.Provide(func() *zap.Logger {
  133. cfg := zap.NewDevelopmentConfig()
  134. cfg.Level.SetLevel(zap.ErrorLevel)
  135. logger, _ := cfg.Build()
  136. return logger
  137. }),
  138. fx.Option(fx.WithLogger(
  139. func(logger *zap.Logger) fxevent.Logger {
  140. return &fxevent.ZapLogger{Logger: logger}
  141. },
  142. )),
  143. ).
  144. Run()
  145. }
  146. func Ptr[T any](v T) *T {
  147. return &v
  148. }
  149. ```

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.