
pjullrich/emcp
Developer tools이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요. 원문 보기
Elixir의 모델 Context Protocol (MCP) 서버
개요
최소 Elixir MCP (모델 Context Protocol) 서버. Application's start/2에 초기화를 추가하십시오: EMCP를 구현하여 사용자 정의 세션 저장소를 사용할 수 있습니다. SessionStore 행동. StreamableHTTP 전송을 Phoenix 라우터에 추가하십시오. EMCP가 콘텐츠 협상을 처리하기 때문에 어떤 파이프라인 밖에 마운트 : Prompts는 구조화된 메시지를 반환하는 재사용할 수 있는 템플릿입니다: 리소스는 클라이언트가 읽을 수있는 데이터를 노출합니다. 정적 자원에는 고정 URI가 있습니다. 리소스 템플릿 사용 URI 패턴 그래서 클라이언트 동적 콘텐츠를 요청할 수 있습니다: 클라이언트가 리소스/읽을 때, 서버는 정적 자원에 대한 정확한 URI 일치를 삼는다. 아무도 일치하지 않는 경우, 그것은 URI를 하나의 손잡이까지 순서에 각 자원 템플릿을 삼는다.
개요(AI 번역)
최소 Elixir MCP (모델 Context Protocol) 서버.
설치
##1. 세션 저장소 초기화
Application의 start/2에 초기화 세션 저장 추가:
EMCP.SessionStore] 동작을 구현하여 사용자 지정 세션 저장소를 사용할 수 있습니다.
##2. 서버 정의
##3. 수송을 거치십시오
StreamableHTTP 전송을 Phoenix 라우터에 추가하십시오. EMCP가 콘텐츠 협상을 처리하기 때문에 어떤 파이프라인 밖에 마운트 :
4. 서버에 도구 추가
# Prompts의
Prompts는 구조화된 메시지를 반환하는 재사용할 수 있는 템플릿입니다:
자원
리소스는 클라이언트가 읽을 수있는 데이터를 노출합니다. 정적 자원에는 고정 URI가 있습니다.
리소스 템플릿 사용 URI 패턴 그래서 클라이언트 동적 콘텐츠를 요청할 수 있습니다:
클라이언트가 호출 할 때 resources/read, 서버는 먼저 정적 자원에 대한 정확한 URI 일치. 아무도 일치하지 않는 경우, 그것은 URI를 하나의 손잡이까지 순서에 각 자원 템플릿을 삼는다.
근원 유효성
DNS 재조합 공격을 방지하기 위해, 당신은 수송에 원산지 검증을 활성화 할 수 있습니다. 활성화 할 때, Origin 헤더 일치하는 허용 목록이 허용됩니다. Origin] 헤더가 없는 요청(예: CLI 도구에서) 항상 허용됩니다.
이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요.
README
원문 README의 일부입니다. 원문 보기.
EMCP
A minimal Elixir MCP (Model Context Protocol) server.
Setup
1. Initialize the session store
Add the session store initialization to your application’s start/2:
defmodule MyApp.Application do
use Application
def start(_type, _args) do
EMCP.SessionStore.ETS.init()
children = [
# ...
]
Supervisor.start_link(children, strategy: :one_for_one)
end
end
You can use a custom session store by implementing the EMCP.SessionStore behaviour.
2. Define a server
defmodule MyApp.MCPServer do
use EMCP.Server,
name: "my-app",
version: "1.0.0",
tools: [MyApp.Tools.Echo],
prompts: [MyApp.Prompts.CodeReview],
resources: [MyApp.Resources.Readme],
resource_templates: [MyApp.ResourceTemplates.UserProfile],
# You can optionally add these meta fields as well:
title: "My App",
description: "MCP server for My App",
instructions: "Use the tools to interact with My App.",
end
3. Mount the transport
Add the StreamableHTTP transport to your Phoenix router. Mount it outside any pipeline since EMCP handles content negotiation itself:
scope "/mcp" do
forward "/", EMCP.Transport.StreamableHTTP, server: MyApp.MCPServer
end
4. Add tools to your server
defmodule MyApp.Tools.Echo do
@behaviour EMCP.Tool
@impl EMCP.Tool
def name, do: "echo"
@impl EMCP.Tool
def description, do: "Echoes back the provided message"
@impl EMCP.Tool
def input_schema do
%{
type: :object,
properties: %{
message: %{type: :string}
},
required: [:message]
}
end
@impl EMCP.Tool
def call(_conn, %{"message" => message}) do
EMCP.Tool.response([%{"type" => "text", "text" => message}])
end
# Return errors with:
# EMCP.Tool.error("something went wrong")
end
Prompts
Prompts are reusable templates that return structured messages:
defmodule MyApp.Prompts.CodeReview do
@behaviour EMCP.Prompt
@impl EMCP.Prompt
def name, do: "code_review"
@impl EMCP.Prompt
def description, do: "Reviews code with optional focus area"
@impl EMCP.Prompt
def arguments do
[
%{name: "code", description: "The code to review", required: true},
%{name: "focus", description: "Optional area to focus on"}
]
end
@impl EMCP.Prompt
def template(_conn, %{"code" => code} = args) do
focus = args["focus"]
user_text =
if focus,
do: "Review this code, focusing on #{focus}:\n\n#{code}",
else: "Review this code:\n\n#{code}"
%{
"description" => "Code review prompt",
"messages" => [
%{"role" => "user", "content" => %{"type" => "text", "text" => user_text}},
%{"role" => "assistant", "content" => %{"type" => "text", "text" => "I'll review the code you've provided."}}
]
}
end
end
Resources
Resources expose data that clients can read. A static resource has a fixed URI:
설치
This server does not publish a one-line install command.
Open the repository installation guide MCP 초보자라면? mcpskill.org 가이드부터 시작하세요 →설정
{
"mcpServers": {
"my-app": {
"command": "mix",
"args": ["run", "--no-halt"],
"cwd": "/path/to/your/elixir/project"
}
}
}