Skip to content

Commit d3eb93d

Browse files
saqadriStreetLamb
andauthored
First pass at implementing the mcp-agent CLI (#409)
* Initial scaffolding * initial CLI * checkpoint * checkpoint 2 * various updates to cli * fix lint and format * fix: should load secrets.yaml template instead when running init cli command * fix: prevent None values in either mcp-agent secrets and config yaml files from overwriting one another when merging both * fix: when running config check, use get_settings() instead of Settings() to ensure settings are loaded. * fix: handle None values for servers in MCPSettings so it defaults to empty dict and update secrets.yaml template so it does not overwrite mcp servers in config * Inform users to save and close editor to continue when running config edit command * fix: Update openai, anthropic and azure regex for keys cli command * Sort model list by provider and model name * Add filtering support for models list cli command * disable untested commands * lint, format, gen_schema * get rid of accidental otlp exporter changes from another branch * get rid of accidental commit from other branch --------- Co-authored-by: StreetLamb <[email protected]>
1 parent 9ca52f2 commit d3eb93d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+8553
-33
lines changed

LLMS.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ Provides both global fallback and instance-specific context support.
17661766

17671767
**Class: `MCPAgentError`**
17681768
- **Inherits from**: Exception
1769-
- **Description**: Base exception class for FastAgent errors
1769+
-- **Description**: Base exception class for agent errors
17701770

17711771
**Class: `ServerConfigError`**
17721772
- **Inherits from**: MCPAgentError

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ dev = [
100100
]
101101

102102
[project.scripts]
103-
mcp-agent = "mcp_agent.cli.cloud.main:run"
104-
mcp_agent = "mcp_agent.cli.cloud.main:run"
105-
mcpagent = "mcp_agent.cli.cloud.main:run"
103+
mcp-agent = "mcp_agent.cli.main:run"
104+
mcp_agent = "mcp_agent.cli.main:run"
105+
mcpagent = "mcp_agent.cli.main:run"
106106
silsila = "mcp_agent.cli.cloud.main:run"
107107
prompt-server = "mcp_agent.mcp.prompts.__main__:main"
108108

schema/mcp-agent.config.schema.json

Lines changed: 123 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@
160160
],
161161
"title": "Provider",
162162
"type": "string"
163+
},
164+
"base_url": {
165+
"anyOf": [
166+
{
167+
"type": "string"
168+
},
169+
{
170+
"type": "null"
171+
}
172+
],
173+
"default": null,
174+
"title": "Base Url"
163175
}
164176
},
165177
"title": "AnthropicSettings",
@@ -741,8 +753,7 @@
741753
}
742754
],
743755
"default": null,
744-
"title": "Allowed Tools",
745-
"description": "Allow list for tools of given server"
756+
"title": "Allowed Tools"
746757
}
747758
},
748759
"title": "MCPServerSettings",
@@ -763,6 +774,95 @@
763774
"title": "MCPSettings",
764775
"type": "object"
765776
},
777+
"OTelConsoleExporterSettings": {
778+
"additionalProperties": true,
779+
"properties": {
780+
"type": {
781+
"const": "console",
782+
"default": "console",
783+
"title": "Type",
784+
"type": "string"
785+
}
786+
},
787+
"title": "OTelConsoleExporterSettings",
788+
"type": "object"
789+
},
790+
"OTelFileExporterSettings": {
791+
"additionalProperties": true,
792+
"properties": {
793+
"type": {
794+
"const": "file",
795+
"default": "file",
796+
"title": "Type",
797+
"type": "string"
798+
},
799+
"path": {
800+
"anyOf": [
801+
{
802+
"type": "string"
803+
},
804+
{
805+
"type": "null"
806+
}
807+
],
808+
"default": null,
809+
"title": "Path"
810+
},
811+
"path_settings": {
812+
"anyOf": [
813+
{
814+
"$ref": "#/$defs/TracePathSettings"
815+
},
816+
{
817+
"type": "null"
818+
}
819+
],
820+
"default": null
821+
}
822+
},
823+
"title": "OTelFileExporterSettings",
824+
"type": "object"
825+
},
826+
"OTelOTLPExporterSettings": {
827+
"additionalProperties": true,
828+
"properties": {
829+
"type": {
830+
"const": "otlp",
831+
"default": "otlp",
832+
"title": "Type",
833+
"type": "string"
834+
},
835+
"endpoint": {
836+
"anyOf": [
837+
{
838+
"type": "string"
839+
},
840+
{
841+
"type": "null"
842+
}
843+
],
844+
"default": null,
845+
"title": "Endpoint"
846+
},
847+
"headers": {
848+
"anyOf": [
849+
{
850+
"additionalProperties": {
851+
"type": "string"
852+
},
853+
"type": "object"
854+
},
855+
{
856+
"type": "null"
857+
}
858+
],
859+
"default": null,
860+
"title": "Headers"
861+
}
862+
},
863+
"title": "OTelOTLPExporterSettings",
864+
"type": "object"
865+
},
766866
"OpenAISettings": {
767867
"additionalProperties": true,
768868
"description": "Settings for using OpenAI models in the MCP Agent application.",
@@ -856,16 +956,28 @@
856956
"exporters": {
857957
"default": [],
858958
"items": {
859-
"enum": [
860-
"console",
861-
"file",
862-
"otlp"
863-
],
864-
"type": "string"
959+
"discriminator": {
960+
"mapping": {
961+
"console": "#/$defs/OTelConsoleExporterSettings",
962+
"file": "#/$defs/OTelFileExporterSettings",
963+
"otlp": "#/$defs/OTelOTLPExporterSettings"
964+
},
965+
"propertyName": "type"
966+
},
967+
"oneOf": [
968+
{
969+
"$ref": "#/$defs/OTelConsoleExporterSettings"
970+
},
971+
{
972+
"$ref": "#/$defs/OTelFileExporterSettings"
973+
},
974+
{
975+
"$ref": "#/$defs/OTelOTLPExporterSettings"
976+
}
977+
]
865978
},
866979
"title": "Exporters",
867-
"type": "array",
868-
"description": "List of exporters to use (can enable multiple simultaneously)"
980+
"type": "array"
869981
},
870982
"service_name": {
871983
"default": "mcp-agent",
@@ -912,7 +1024,7 @@
9121024
}
9131025
],
9141026
"default": null,
915-
"description": "OTLP settings for OpenTelemetry tracing. Required if using otlp exporter."
1027+
"description": "Deprecated single OTLP settings. Prefer exporters list with type \"otlp\"."
9161028
},
9171029
"path": {
9181030
"anyOf": [
@@ -1165,9 +1277,6 @@
11651277
"type": "null"
11661278
}
11671279
],
1168-
"default": {
1169-
"servers": {}
1170-
},
11711280
"description": "MCP config, such as MCP servers"
11721281
},
11731282
"execution_engine": {

scripts/gen_schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# /// script
22
# requires-python = ">=3.10"
33
# dependencies = [
4+
# "httpx",
45
# "rich",
56
# "typer",
67
# "pydantic>=2.10.4",

src/mcp_agent/cli/__main__.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import sys
2+
3+
from mcp_agent.cli.main import app
4+
5+
6+
GO_OPTIONS = {
7+
"--npx",
8+
"--uvx",
9+
"--stdio",
10+
"--url",
11+
"--model",
12+
"--models",
13+
"--instruction",
14+
"-i",
15+
"--message",
16+
"-m",
17+
"--prompt-file",
18+
"-p",
19+
"--servers",
20+
"--auth",
21+
"--name",
22+
"--config-path",
23+
"-c",
24+
"--script",
25+
}
26+
27+
KNOWN = {
28+
"go",
29+
"check",
30+
"chat",
31+
"dev",
32+
"invoke",
33+
"serve",
34+
"init",
35+
"quickstart",
36+
"config",
37+
"keys",
38+
"models",
39+
"server",
40+
"build",
41+
"logs",
42+
"doctor",
43+
"configure",
44+
"cloud",
45+
}
46+
47+
48+
def main():
49+
if len(sys.argv) > 1:
50+
first = sys.argv[1]
51+
if first not in KNOWN:
52+
for i, arg in enumerate(sys.argv[1:], 1):
53+
if arg in GO_OPTIONS or any(
54+
arg.startswith(opt + "=") for opt in GO_OPTIONS
55+
):
56+
sys.argv.insert(i, "go")
57+
break
58+
app()
59+
60+
61+
if __name__ == "__main__":
62+
main()

src/mcp_agent/cli/cloud/main.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,9 @@ def invoke(self, ctx):
108108

109109

110110
# Deployment command
111-
app.command(
112-
name="deploy",
113-
help="Deploy an MCP agent (alias for 'cloud deploy')"
114-
)(deploy_config)
111+
app.command(name="deploy", help="Deploy an MCP agent (alias for 'cloud deploy')")(
112+
deploy_config
113+
)
115114

116115

117116
# Sub-typer for `mcp-agent apps` commands
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
Command group entrypoints for the mcp-agent CLI (non-cloud).
3+
4+
Each module exposes a Typer app named `app` which is mounted by
5+
`mcp_agent.cli.main` under an appropriate command group.
6+
"""
7+
8+
from . import (
9+
chat,
10+
dev,
11+
invoke,
12+
serve,
13+
init,
14+
quickstart,
15+
config,
16+
keys,
17+
models,
18+
server,
19+
build,
20+
logs,
21+
doctor,
22+
configure,
23+
go,
24+
check,
25+
) # noqa: F401
26+
27+
__all__ = [
28+
"chat",
29+
"dev",
30+
"invoke",
31+
"serve",
32+
"init",
33+
"quickstart",
34+
"config",
35+
"keys",
36+
"models",
37+
"server",
38+
"build",
39+
"logs",
40+
"doctor",
41+
"configure",
42+
"go",
43+
"check",
44+
]

0 commit comments

Comments
 (0)