Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
zcaceres authored Dec 18, 2024
2 parents 3ba8a0e + 926d86c commit 91bac3c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/everything/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Everything MCP Server
# Everything MCP Server

This MCP server attempts to exercise all the features of the MCP protocol. It is not intended to be a useful server, but rather a test server for builders of MCP clients. It implements prompts, tools, resources, sampling, and more to showcase MCP capabilities.

Expand All @@ -15,7 +15,7 @@ This MCP server attempts to exercise all the features of the MCP protocol. It is
2. `add`
- Adds two numbers together
- Inputs:
- `a` (number): First number
- `a` (number): First number
- `b` (number): Second number
- Returns: Text result of the addition

Expand All @@ -27,7 +27,7 @@ This MCP server attempts to exercise all the features of the MCP protocol. It is
- Returns: Completion message with duration and steps
- Sends progress notifications during execution

4. `sampleLLM`
4. `sampleLLM`
- Demonstrates LLM sampling capability using MCP sampling feature
- Inputs:
- `prompt` (string): The prompt to send to the LLM
Expand All @@ -39,17 +39,23 @@ This MCP server attempts to exercise all the features of the MCP protocol. It is
- No inputs required
- Returns: Base64 encoded PNG image data

6. `printEnv`
- Prints all environment variables
- Useful for debugging MCP server configuration
- No inputs required
- Returns: JSON string of all environment variables

### Resources

The server provides 100 test resources in two formats:
- Even numbered resources:
- Even numbered resources:
- Plaintext format
- URI pattern: `test://static/resource/{even_number}`
- Content: Simple text description

- Odd numbered resources:
- Binary blob format
- URI pattern: `test://static/resource/{odd_number}`
- URI pattern: `test://static/resource/{odd_number}`
- Content: Base64 encoded binary data

Resource features:
Expand Down
19 changes: 19 additions & 0 deletions src/everything/everything.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const LongRunningOperationSchema = z.object({
steps: z.number().default(5).describe("Number of steps in the operation"),
});

const PrintEnvSchema = z.object({});

const SampleLLMSchema = z.object({
prompt: z.string().describe("The prompt to send to the LLM"),
maxTokens: z
Expand All @@ -54,6 +56,7 @@ enum ToolName {
ECHO = "echo",
ADD = "add",
LONG_RUNNING_OPERATION = "longRunningOperation",
PRINT_ENV = "printEnv",
SAMPLE_LLM = "sampleLLM",
GET_TINY_IMAGE = "getTinyImage",
}
Expand Down Expand Up @@ -297,6 +300,11 @@ export const createServer = () => {
description: "Adds two numbers",
inputSchema: zodToJsonSchema(AddSchema) as ToolInput,
},
{
name: ToolName.PRINT_ENV,
description: "Prints all environment variables, helpful for debugging MCP server configuration",
inputSchema: zodToJsonSchema(PrintEnvSchema) as ToolInput,
},
{
name: ToolName.LONG_RUNNING_OPERATION,
description:
Expand Down Expand Up @@ -374,6 +382,17 @@ export const createServer = () => {
};
}

if (name === ToolName.PRINT_ENV) {
return {
content: [
{
type: "text",
text: JSON.stringify(process.env, null, 2),
},
],
};
}

if (name === ToolName.SAMPLE_LLM) {
const validatedArgs = SampleLLMSchema.parse(args);
const { prompt, maxTokens } = validatedArgs;
Expand Down
6 changes: 6 additions & 0 deletions src/git/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ Please note that mcp-server-git is currently in early development. The functiona
- `repo_path` (string): Path to Git repository
- `branch_name` (string): Name of branch to checkout
- Returns: Confirmation of branch switch
9. `git_show`
- Shows the contents of a commit
- Inputs:
- `repo_path` (string): Path to Git repository
- `revision` (string): The revision (commit hash, branch name, tag) to show
- Returns: Contents of the specified commit

## Installation

Expand Down
35 changes: 35 additions & 0 deletions src/git/src/mcp_server_git/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class GitCheckout(BaseModel):
repo_path: str
branch_name: str

class GitShow(BaseModel):
repo_path: str
revision: str

class GitTools(str, Enum):
STATUS = "git_status"
DIFF_UNSTAGED = "git_diff_unstaged"
Expand All @@ -63,6 +67,7 @@ class GitTools(str, Enum):
LOG = "git_log"
CREATE_BRANCH = "git_create_branch"
CHECKOUT = "git_checkout"
SHOW = "git_show"

def git_status(repo: git.Repo) -> str:
return repo.git.status()
Expand Down Expand Up @@ -113,6 +118,24 @@ def git_checkout(repo: git.Repo, branch_name: str) -> str:
repo.git.checkout(branch_name)
return f"Switched to branch '{branch_name}'"

def git_show(repo: git.Repo, revision: str) -> str:
commit = repo.commit(revision)
output = [
f"Commit: {commit.hexsha}\n"
f"Author: {commit.author}\n"
f"Date: {commit.authored_datetime}\n"
f"Message: {commit.message}\n"
]
if commit.parents:
parent = commit.parents[0]
diff = parent.diff(commit, create_patch=True)
else:
diff = commit.diff(git.NULL_TREE, create_patch=True)
for d in diff:
output.append(f"\n--- {d.a_path}\n+++ {d.b_path}\n")
output.append(d.diff.decode('utf-8'))
return "".join(output)

async def serve(repository: Path | None) -> None:
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -179,6 +202,11 @@ async def list_tools() -> list[Tool]:
description="Switches branches",
inputSchema=GitCheckout.schema(),
),
Tool(
name=GitTools.SHOW,
description="Shows the contents of a commit",
inputSchema=GitShow.schema(),
)
]

async def list_repos() -> Sequence[str]:
Expand Down Expand Up @@ -290,6 +318,13 @@ async def call_tool(name: str, arguments: dict) -> list[TextContent]:
text=result
)]

case GitTools.SHOW:
result = git_show(repo, arguments["revision"])
return [TextContent(
type="text",
text=result
)]

case _:
raise ValueError(f"Unknown tool: {name}")

Expand Down

0 comments on commit 91bac3c

Please sign in to comment.