Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement current developer system as a separate mcp server #514

Merged
merged 9 commits into from
Dec 30, 2024
32 changes: 32 additions & 0 deletions crates/developer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "developer"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
description.workspace = true

[dependencies]
mcp-core = { path = "../mcp-core" }
mcp-server = { path = "../mcp-server" }
anyhow = "1.0.94"
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-appender = "0.2"
url = "2.5"
urlencoding = "2.1.3"
base64 = "0.21"
thiserror = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_urlencoded = "0.7"
lazy_static = "1.5"
kill_tree = "0.2.4"
shellexpand = "3.1.0"
indoc = "2.0.5"

[dev-dependencies]
sysinfo = "0.32.1"
tempfile = "3.8"
7 changes: 7 additions & 0 deletions crates/developer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Test with MCP Inspector

```bash
npx @modelcontextprotocol/inspector cargo run -p developer
```

Then visit the Inspector in the browser window and test the different endpoints.
69 changes: 69 additions & 0 deletions crates/developer/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use mcp_core::handler::{ResourceError, ToolError};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like file this should maybe be part of more central library? but i guess reasonable to wait until we have another (although @michaelneale has a new system that would need these i think)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually after reading, maybe we remove this entirely and only use ToolError from mcp_core

use mcp_server::RouterError;
use serde::{Deserialize, Serialize};
use thiserror::Error;

#[non_exhaustive]
#[derive(Error, Debug, Clone, Deserialize, Serialize, PartialEq)]
pub enum AgentError {
#[error("Tool not found: {0}")]
ToolNotFound(String),

#[error("The parameters to the tool call were invalid: {0}")]
InvalidParameters(String),

#[error("The tool failed during execution with the following output: \n{0}")]
ExecutionError(String),

#[error("Internal error: {0}")]
Internal(String),

#[error("Invalid tool name: {0}")]
InvalidToolName(String),
}

pub type AgentResult<T> = Result<T, AgentError>;

impl From<AgentError> for ToolError {
fn from(err: AgentError) -> Self {
match err {
AgentError::InvalidParameters(msg) => ToolError::InvalidParameters(msg),
AgentError::InvalidToolName(msg) => ToolError::InvalidParameters(msg),
AgentError::ToolNotFound(msg) => ToolError::NotFound(msg),
AgentError::ExecutionError(msg) => ToolError::ExecutionError(msg),
AgentError::Internal(msg) => ToolError::ExecutionError(msg),
}
}
}

impl From<AgentError> for ResourceError {
fn from(err: AgentError) -> Self {
match err {
AgentError::InvalidParameters(msg) => ResourceError::NotFound(msg),
_ => ResourceError::NotFound(err.to_string()),
}
}
}

impl From<AgentError> for RouterError {
fn from(err: AgentError) -> Self {
match err {
AgentError::ToolNotFound(msg) => RouterError::ToolNotFound(msg),
AgentError::InvalidParameters(msg) => RouterError::InvalidParams(msg),
AgentError::ExecutionError(msg) => RouterError::Internal(msg),
AgentError::Internal(msg) => RouterError::Internal(msg),
AgentError::InvalidToolName(msg) => RouterError::ToolNotFound(msg),
}
}
}

impl From<ResourceError> for AgentError {
fn from(err: ResourceError) -> Self {
match err {
ResourceError::NotFound(msg) => {
AgentError::InvalidParameters(format!("Resource not found: {}", msg))
}
ResourceError::ExecutionError(msg) => AgentError::ExecutionError(msg),
}
}
}
34 changes: 34 additions & 0 deletions crates/developer/src/lang.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::path::Path;

/// Get the markdown language identifier for a file extension
pub fn get_language_identifier(path: &Path) -> &'static str {
match path.extension().and_then(|ext| ext.to_str()) {
Some("rs") => "rust",
Some("py") => "python",
Some("js") => "javascript",
Some("ts") => "typescript",
Some("json") => "json",
Some("toml") => "toml",
Some("yaml") | Some("yml") => "yaml",
Some("sh") => "bash",
Some("go") => "go",
Some("md") => "markdown",
Some("html") => "html",
Some("css") => "css",
Some("sql") => "sql",
Some("java") => "java",
Some("cpp") | Some("cc") | Some("cxx") => "cpp",
Some("c") => "c",
Some("h") | Some("hpp") => "cpp",
Some("rb") => "ruby",
Some("php") => "php",
Some("swift") => "swift",
Some("kt") | Some("kts") => "kotlin",
Some("scala") => "scala",
Some("r") => "r",
Some("m") => "matlab",
Some("pl") => "perl",
Some("dockerfile") => "dockerfile",
_ => "",
}
}
Loading
Loading