MCP ExplorerExplorer

Mcp Gleam

@ryanmivilleon 15 days ago
1 MIT
FreeCommunity
AI Systems
Gleamcp is a server interface for the MCP protocol, managing connections and message routing.

Overview

What is Mcp Gleam

mcp-gleam is a server implementation for the MCP protocol, designed to facilitate connection management, protocol compliance, and message routing.

Use cases

Use cases for mcp-gleam include building APIs, serving static files, and integrating with large language models (LLMs) for data exposure.

How to use

To use mcp-gleam, you can add it to your project with the command ‘gleam add gleamcp@1’. Then, import it in your code and create a server instance to handle requests and resources.

Key features

Key features include server creation, resource management, support for static and dynamic resources, and a straightforward API for handling requests.

Where to use

mcp-gleam can be used in various fields such as web development, data processing, and applications that require real-time communication and resource management.

Content

gleamcp

Package Version
Hex Docs

gleam add gleamcp@1
import gleamcp

pub fn main() -> Nil {
  // TODO: An example of the project in use
}

Further documentation can be found at https://hexdocs.pm/gleamcp.

Development

gleam run   # Run the project
gleam test  # Run the tests

Core Concepts

Server

Show Server Examples

The server is your core interface to the MCP protocol. It handles connection management, protocol compliance, and message routing:

let srv = server.new("My Server", "1.0.0")

server.serve_stdio(srv) // Result(Pid?, StartError)
process.sleep_forever()

Resources

Show Resource Examples Resources are how you expose data to LLMs. They can be anything - files, API responses, database queries, system information, etc. Resources can be:
  • Static (fixed URI)
  • Dynamic (using URI templates)

Here’s a simple example of a static resource:

// static resource example - exposing a README file
let res = resource.new("docs://readme", "Project README")
  |> resource.description("The project's README file")
  |> resource.mime_type("text/markdown")

server.new()
  |> server.add_resource(res, fn(req) {
    let content = simplifile.read_file("README.md")
    resource.TextContents(
      uri: "docs://readme",
      mime_type: "text/markdown",
      text: content,
    )
  })

Unsupported Features

  • batch messages
  • resource subscribe
  • pagination (it returns all resources, etc.)
  • resource templates (need a uri template lib)
  • server notifications (resources cannot change yet)
  • _meta field
  • experimental field

Tools

No tools

Comments