ritikjain51 commited on
Commit
2ef9bf7
·
verified ·
1 Parent(s): a9a559d

Upload 7 files

Browse files
Files changed (7) hide show
  1. __init__.py +4 -0
  2. file_explorer.py +73 -0
  3. gradio_app.py +12 -0
  4. mcp.json +47 -0
  5. requirements.txt +3 -0
  6. sentiment_tools.py +33 -0
  7. server.py +24 -0
__init__.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ # E2E MCP Module
2
+ """
3
+ End-to-End MCP server implementations for diverse use cases.
4
+ """
file_explorer.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # File explorer tools
2
+ """
3
+ MCP tools for exploring files and directories.
4
+ """
5
+ import os
6
+ from mcp.server.fastmcp import FastMCP
7
+
8
+
9
+ def register_file_explorer_tools(mcp: FastMCP):
10
+ """Register file explorer tools with the MCP server."""
11
+
12
+ @mcp.tool()
13
+ def list_directory(path: str) -> list:
14
+ """
15
+ List contents of a directory.
16
+
17
+ Args:
18
+ path: Directory path to list
19
+
20
+ Returns:
21
+ List of files and directories
22
+ """
23
+ if not os.path.exists(path):
24
+ return {"error": f"Path {path} does not exist"}
25
+
26
+ if not os.path.isdir(path):
27
+ return {"error": f"Path {path} is not a directory"}
28
+
29
+ try:
30
+ contents = os.listdir(path)
31
+ result = []
32
+
33
+ for item in contents:
34
+ item_path = os.path.join(path, item)
35
+ item_type = "directory" if os.path.isdir(item_path) else "file"
36
+
37
+ result.append({
38
+ "name": item,
39
+ "type": item_type,
40
+ "path": item_path
41
+ })
42
+
43
+ return result
44
+ except Exception as e:
45
+ return {"error": str(e)}
46
+
47
+ @mcp.tool()
48
+ def file_info(path: str) -> dict:
49
+ """
50
+ Get information about a file.
51
+
52
+ Args:
53
+ path: Path to the file
54
+
55
+ Returns:
56
+ Information about the file
57
+ """
58
+ if not os.path.exists(path):
59
+ return {"error": f"Path {path} does not exist"}
60
+
61
+ try:
62
+ stat_info = os.stat(path)
63
+
64
+ return {
65
+ "name": os.path.basename(path),
66
+ "path": os.path.abspath(path),
67
+ "size": stat_info.st_size,
68
+ "last_modified": stat_info.st_mtime,
69
+ "is_directory": os.path.isdir(path),
70
+ "is_file": os.path.isfile(path)
71
+ }
72
+ except Exception as e:
73
+ return {"error": str(e)}
gradio_app.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from sentiment_tools import analyze_sentiment
4
+
5
+ demo = gr.Interface(fn=analyze_sentiment,
6
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
7
+ outputs=gr.JSON(),
8
+ title="Sentiment Analysis",
9
+ description="Enter text to analyze its sentiment.")
10
+ if __name__ == "__main__":
11
+ # Launch the Gradio UI for sentiment analysis
12
+ demo.launch(mcp_server=True)
mcp.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "servers": [
3
+ {
4
+ "name": "E2E MCP Server",
5
+ "transport": {
6
+ "type": "stdio",
7
+ "command": "python",
8
+ "args": [
9
+ "./server.py"
10
+ ]
11
+ }
12
+ },
13
+ {
14
+ "name": "Sentiment Analysis Server",
15
+ "transport": {
16
+ "type": "stdio",
17
+ "command": "python",
18
+ "args": [
19
+ "-c",
20
+ "from e2e_mcp.sentiment_tools import register_sentiment_tool; from mcp.server.fastmcp import FastMCP; mcp = FastMCP('SentimentTools'); register_sentiment_tool(mcp); mcp.run()"
21
+ ]
22
+ }
23
+ },
24
+ {
25
+ "name": "File Explorer Server",
26
+ "transport": {
27
+ "type": "stdio",
28
+ "command": "python",
29
+ "args": [
30
+ "-c",
31
+ "from e2e_mcp.file_explorer import register_file_explorer_tools; from mcp.server.fastmcp import FastMCP; mcp = FastMCP('FileExplorerTools'); register_file_explorer_tools(mcp); mcp.run()"
32
+ ]
33
+ }
34
+ },
35
+
36
+ {
37
+ "gradio": {
38
+ "command": "npx",
39
+ "args": [
40
+ "mcp-remote",
41
+ "http://localhost:7860/gradio_api/mcp/sse"
42
+ ]
43
+ }
44
+ }
45
+
46
+ ]
47
+ }
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ textblob>=0.15.3
2
+ gradio>=3.50.0
3
+ gradio[mcp]
sentiment_tools.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from textblob import TextBlob
2
+
3
+ def analyze_sentiment(text):
4
+ """Analyze the sentiment of a given text.
5
+ Args:
6
+ text (str): The text to analyze
7
+ Returns:
8
+ dict: A dictionary containing polarity, subjectivity, and assessment
9
+ """
10
+ blob = TextBlob(text)
11
+
12
+ return {
13
+ "polarity": round(blob.polarity, 2),
14
+ "subjectivity": round(blob.subjectivity, 2),
15
+ "assessment": "positive" if blob.polarity > 0 else "negative" if blob.polarity < 0 else "neutral"
16
+ }
17
+
18
+
19
+ def register_sentiment_tool(mcp):
20
+ """Register the sentiment analysis tool with the MCP server."""
21
+
22
+ @mcp.tool()
23
+ def sentiment_analysis(text: str) -> dict:
24
+ """
25
+ Analyze the sentiment of a given text.
26
+
27
+ Args:
28
+ text: The text to analyze
29
+
30
+ Returns:
31
+ A dictionary with polarity, subjectivity, and assessment
32
+ """
33
+ return analyze_sentiment(text)
server.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Main E2E MCP Server
2
+ """
3
+ Main MCP server integrating all E2E tools.
4
+ """
5
+ from mcp.server.fastmcp import FastMCP
6
+ from sentiment_tools import register_sentiment_tool
7
+ from file_explorer import register_file_explorer_tools
8
+
9
+
10
+ def create_server(name="E2EMCP"):
11
+ """Create and configure the E2E MCP server instance."""
12
+ mcp = FastMCP(name)
13
+
14
+ # Register all tools
15
+ register_sentiment_tool(mcp)
16
+ register_file_explorer_tools(mcp)
17
+
18
+ return mcp
19
+
20
+
21
+ # if __name__ == "__main__":
22
+ # # Create and start the server
23
+ mcp = create_server()
24
+ mcp.run()