abhishekrn commited on
Commit
6b02c16
Β·
1 Parent(s): 8acbaa7

refactor: restructure project and add comprehensive gitignore

Browse files

- Move prompts from src/infrastructure/prompts to config/
- Restructure project with clean architecture (src/application, src/domain, src/infrastructure, src/presentation)
- Add comprehensive .gitignore for Python/AI/ML projects
- Clean up cache files, coverage reports, and temporary files
- Move backup_v1 to preserve old structure
- Update imports and fix member API parameter extraction
- Add proper project configuration with pyproject.toml

This view is limited to 50 files because it contains too many changes. Β  See raw diff
Files changed (50) hide show
  1. .gitignore +277 -0
  2. README.md +95 -161
  3. SETUP.md +75 -0
  4. app/.gradio/flagged/dataset1.csv +0 -15
  5. app/__pycache__/main.cpython-313.pyc +0 -0
  6. app/agent/__pycache__/__init__.cpython-313.pyc +0 -0
  7. app/agent/__pycache__/model_client.cpython-313.pyc +0 -0
  8. app/agent/__pycache__/prompt_engine.cpython-313.pyc +0 -0
  9. app/agent/__pycache__/schema.cpython-313.pyc +0 -0
  10. app/agent/__pycache__/tool_executor.cpython-313.pyc +0 -0
  11. app/config/__pycache__/__init__.cpython-313.pyc +0 -0
  12. app/config/__pycache__/api_endpoints.cpython-313.pyc +0 -0
  13. app/config/__pycache__/api_specs.cpython-313.pyc +0 -0
  14. app/config/__pycache__/compact_api_specs.cpython-313.pyc +0 -0
  15. app/config/__pycache__/settings.cpython-313.pyc +0 -0
  16. app/config/__pycache__/static_responses.cpython-313.pyc +0 -0
  17. app/mcp/__pycache__/__init__.cpython-313.pyc +0 -0
  18. app/mcp/__pycache__/adapter.cpython-313.pyc +0 -0
  19. app/mcp/__pycache__/analyzers.cpython-313.pyc +0 -0
  20. app/mcp/__pycache__/cache.cpython-313.pyc +0 -0
  21. app/mcp/__pycache__/catalog.cpython-313.pyc +0 -0
  22. app/mcp/__pycache__/catalog_utils.cpython-313.pyc +0 -0
  23. app/mcp/__pycache__/compact_utils.cpython-313.pyc +0 -0
  24. app/mcp/__pycache__/http.cpython-313.pyc +0 -0
  25. app/mcp/__pycache__/mcp_client.cpython-313.pyc +0 -0
  26. app/mcp/__pycache__/registry.cpython-313.pyc +0 -0
  27. app/mcp/__pycache__/specs_generator.cpython-313.pyc +0 -0
  28. app/mcp/__pycache__/stream_client.cpython-313.pyc +0 -0
  29. app/prompts/__pycache__/api_param_extraction_prompt.cpython-313.pyc +0 -0
  30. app/prompts/__pycache__/default_responses.cpython-313.pyc +0 -0
  31. app/prompts/__pycache__/system_prompts.cpython-313.pyc +0 -0
  32. app/prompts/__pycache__/tool_prompts.cpython-313.pyc +0 -0
  33. app/ui/__pycache__/__init__.cpython-313.pyc +0 -0
  34. app/ui/__pycache__/interface.cpython-313.pyc +0 -0
  35. app/utils/__pycache__/json_filter.cpython-313.pyc +0 -0
  36. __init__.py β†’ backup_v1/agent/__init__.py +0 -0
  37. {app β†’ backup_v1}/agent/model_client.py +0 -0
  38. {app β†’ backup_v1}/agent/prompt_engine.py +0 -0
  39. {app β†’ backup_v1}/agent/schema.py +0 -0
  40. {app β†’ backup_v1}/agent/tool_executor.py +0 -0
  41. {app/agent β†’ backup_v1/config}/__init__.py +0 -0
  42. {app β†’ backup_v1}/config/api_endpoints.py +0 -0
  43. {app β†’ backup_v1}/config/compact_api_specs.py +0 -0
  44. {app β†’ backup_v1}/config/settings.py +0 -0
  45. {app β†’ backup_v1}/config/static_responses.py +0 -0
  46. {app β†’ backup_v1}/main.py +0 -0
  47. backup_v1/mcp-config.json +8 -0
  48. {app/config β†’ backup_v1/mcp}/__init__.py +0 -0
  49. {app β†’ backup_v1}/mcp/analyzers.py +0 -0
  50. {app β†’ backup_v1}/mcp/catalog.py +0 -0
.gitignore ADDED
@@ -0,0 +1,277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be added to the global gitignore or merged into this project gitignore. For a PyCharm
158
+ # project, it is recommended to include the following files:
159
+ # .idea/
160
+ # *.iml
161
+ # *.ipr
162
+ # *.iws
163
+
164
+ # VS Code
165
+ .vscode/
166
+
167
+ # macOS
168
+ .DS_Store
169
+ .AppleDouble
170
+ .LSOverride
171
+
172
+ # Icon must end with two \r
173
+ Icon
174
+
175
+ # Thumbnails
176
+ ._*
177
+
178
+ # Files that might appear in the root of a volume
179
+ .DocumentRevisions-V100
180
+ .fseventsd
181
+ .Spotlight-V100
182
+ .TemporaryItems
183
+ .Trashes
184
+ .VolumeIcon.icns
185
+ .com.apple.timemachine.donotpresent
186
+
187
+ # Directories potentially created on remote AFP share
188
+ .AppleDB
189
+ .AppleDesktop
190
+ Network Trash Folder
191
+ Temporary Items
192
+ .apdisk
193
+
194
+ # Windows
195
+ Thumbs.db
196
+ Thumbs.db:encryptable
197
+ ehthumbs.db
198
+ ehthumbs_vista.db
199
+
200
+ # Dump file
201
+ *.stackdump
202
+
203
+ # Folder config file
204
+ [Dd]esktop.ini
205
+
206
+ # Recycle Bin used on file shares
207
+ $RECYCLE.BIN/
208
+
209
+ # Windows Installer files
210
+ *.cab
211
+ *.msi
212
+ *.msix
213
+ *.msm
214
+ *.msp
215
+
216
+ # Windows shortcuts
217
+ *.lnk
218
+
219
+ # Linux
220
+ *~
221
+
222
+ # temporary files which can be created if a process still has a handle open of a deleted file
223
+ .fuse_hidden*
224
+
225
+ # KDE directory preferences
226
+ .directory
227
+
228
+ # Linux trash folder which might appear on any partition or disk
229
+ .Trash-*
230
+
231
+ # .nfs files are created when an open file is removed but is still being accessed
232
+ .nfs*
233
+
234
+ # AI/ML specific
235
+ *.h5
236
+ *.hdf5
237
+ *.pkl
238
+ *.pickle
239
+ *.joblib
240
+ *.model
241
+ *.weights
242
+ *.ckpt
243
+ *.pt
244
+ *.pth
245
+ *.onnx
246
+ *.tflite
247
+ *.pb
248
+
249
+ # Hugging Face cache
250
+ .cache/
251
+ huggingface/
252
+
253
+ # Gradio
254
+ .gradio/
255
+
256
+ # MCP specific
257
+ mcp_catalog/
258
+ *.mcp
259
+
260
+ # Logs
261
+ *.log
262
+ logs/
263
+
264
+ # Temporary files
265
+ *.tmp
266
+ *.temp
267
+ temp/
268
+ tmp/
269
+
270
+ # IDE specific
271
+ .idea/
272
+ *.swp
273
+ *.swo
274
+ *~
275
+
276
+ # Project specific
277
+ backup_v1/ # Keep this for now as it's referenced in docs
README.md CHANGED
@@ -1,193 +1,127 @@
1
- # Topcoder MCP Agent
2
 
3
- A configurable MCP (Model Context Protocol) agent for Topcoder that can work with different LLM providers.
4
 
5
- ## Configuration
6
 
7
- ### Environment Variables
8
 
9
- Create a `.env` file in the project root with the following variables:
 
 
 
 
 
 
 
10
 
11
- ```bash
12
- # LLM Configuration
13
- HF_TOKEN=your_huggingface_token
14
- HF_MODEL=Qwen/Qwen2.5-7B-Instruct:together
15
- LLM_API_URL=https://router.huggingface.co/v1/chat/completions
16
- LLM_TEMPERATURE=0.8
17
 
18
- # MCP Configuration
19
- MCP_SERVER_URL=https://api.topcoder-dev.com/v6/mcp/mcp
20
- MCP_TOKEN=your_mcp_token
21
 
22
- # API Authentication Configuration
23
- EXCLUDE_AUTH_REQUIRED_ENDPOINTS=true
24
- EXCLUDE_401_RESPONSES=true
25
- STRICT_AUTH_FILTERING=false
26
- ```
27
 
28
- ### Authentication Filtering Options
 
29
 
30
- The system includes configurable authentication filtering to exclude endpoints that require authentication:
 
 
31
 
32
- - **`EXCLUDE_AUTH_REQUIRED_ENDPOINTS`** (default: `true`): Enable/disable authentication filtering
33
- - **`EXCLUDE_401_RESPONSES`** (default: `true`): Filter out endpoints that have 401 responses in documentation
34
- - **`STRICT_AUTH_FILTERING`** (default: `false`): More aggressive filtering based on authentication keywords in descriptions
35
 
36
- This ensures that only publicly accessible APIs are included in the compact specs when no authentication is configured.
37
 
38
- ## Example .env file
39
- ```
40
  HF_TOKEN=your_huggingface_token_here
41
  HF_MODEL=Qwen/Qwen2.5-7B-Instruct:together
42
- LLM_API_URL=https://router.huggingface.co/v1/chat/completions
43
- LLM_TEMPERATURE=0.8
44
- MCP_BASE_URL=https://api.topcoder-dev.com/v6/mcp/mcp
45
- MCP_SERVER_URL=https://api.topcoder-dev.com/v6/mcp/mcp
46
- MCP_TOKEN=your_mcp_token_here
47
- ```
48
 
49
- ## Usage
 
50
 
51
- 1. Run the setup script to create a default `.env` file:
52
- ```bash
53
- python setup.py
 
54
  ```
55
 
56
- 2. Install dependencies:
57
- ```bash
58
- pip install -r requirements.txt
59
- ```
60
 
61
- 3. Update the `.env` file with your actual API tokens and URLs
62
 
63
- 4. Run the application:
64
  ```bash
65
- python -m app.main
66
- ```
67
-
68
- The application will automatically:
69
- - Connect to the MCP server
70
- - Discover available tools and resources
71
- - Catalog tool schemas and analyze API documentation
72
- - Store structured data in the `mcp_catalog/` directory
73
-
74
- ### Using Cataloged Data
75
-
76
- The cataloged data can be accessed programmatically:
77
 
78
- ```python
79
- from app.mcp.catalog_utils import CatalogUtils
80
-
81
- utils = CatalogUtils()
82
-
83
- # Get tool schema
84
- tool_schema = utils.get_tool_schema("query-tc-challenges")
85
 
86
- # Format a tool request
87
- request = utils.format_tool_request("query-tc-challenges", {
88
- "status": "Active",
89
- "perPage": 10
90
- })
91
 
92
- # Find API endpoints
93
- endpoint = utils.find_api_endpoint("Challenges V6 API Swagger", "/challenges", "GET")
94
 
95
- ### Using Compact API Specs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
- The system also generates compact API specs that are much smaller and only include working tools/resources:
98
 
99
- ```python
100
- from app.mcp.compact_utils import CompactSpecsUtils
 
 
 
 
101
 
102
- utils = CompactSpecsUtils()
 
 
103
 
104
- # Get working tools
105
- working_tools = utils.get_working_tools()
 
 
106
 
107
- # Format a tool request using compact specs
108
- request = utils.format_tool_request("query-tc-challenges", {
109
- "status": "Active",
110
- "perPage": 10
111
- })
112
 
113
- # Get resource endpoints
114
- endpoints = utils.get_resource_endpoints("Challenges_V6_API_Swagger")
115
- ```
116
 
117
- ### Dynamic Tool Execution
118
-
119
- The agent now uses compact specs for dynamic tool execution instead of hardcoded prompts:
120
-
121
- ```python
122
- from app.agent.prompt_engine import PromptBuilder
123
- from app.agent.tool_executor import ToolExecutor
124
-
125
- # Dynamic prompt generation
126
- prompt_builder = PromptBuilder()
127
- prompt = prompt_builder.build_tool_decision_prompt("Show me active challenges")
128
-
129
- # Dynamic tool execution
130
- tool_executor = ToolExecutor()
131
- available_tools = tool_executor.get_available_tools() # ['query-tc-skills', 'query-tc-challenges']
132
- available_resources = tool_executor.get_available_resources() # ['Challenges_V6_API_Swagger', 'Member_V6_API_Swagger', 'Identity_V6_API_Swagger']
133
-
134
- # Format resource requests
135
- resource_request = tool_executor.compact_utils.format_resource_request(
136
- "Challenges_V6_API_Swagger",
137
- "/challenges",
138
- "GET",
139
- {"status": "Active"}
140
- )
141
-
142
- # Make direct API calls with parameter substitution
143
- result = await tool_executor.compact_utils.make_direct_api_call(
144
- "Member_V6_API_Swagger",
145
- "/members/abhishekrn", # Path parameters are substituted
146
- "GET"
147
- )
148
-
149
- # Or with query parameters (using hardcoded base URL)
150
- result = await tool_executor.compact_utils.make_direct_api_call(
151
- "Challenges_V6_API_Swagger",
152
- "/challenges",
153
- "GET",
154
- {"status": "Active", "track": "Development", "totalPrizesFrom": "1000", "sortBy": "overview.totalPrizes", "sortOrder": "desc", "perPage": "20"}
155
- )
156
-
157
- **Key Improvements:**
158
- - **Simplified Prompts**: Dynamic prompts are concise and focused
159
- - **Parameter Cleaning**: Empty parameters are automatically filtered out
160
- - **Better Tool Selection**: Clear usage instructions for each tool
161
- - **Parameter Extraction**: Automatic extraction when parameters are missing
162
- - **Validation**: Tools are validated against compact specs before execution
163
- - **Resource Support**: Can now execute both tools and API resources
164
- - **Dynamic Endpoints**: Resources include key endpoints for API calls
165
- - **Direct API Calls**: Resources can make direct API calls using extracted base URLs
166
- - **Base URL Extraction**: Automatically extracts API base URLs from OpenAPI documents
167
- - **Version Handling**: Properly handles API versions from swagger documents
168
- - **Correct URL Format**: Uses `https://api.topcoder.com/v5/` format for all Topcoder APIs
169
- - **Parameter Extraction**: Automatically extracts parameters from user queries for both tools and resources
170
- - **Path Substitution**: Correctly substitutes path parameters (e.g., `{handle}` β†’ `abhishekrn`) in API endpoints
171
-
172
- ## Features
173
-
174
- - Generic LLM client that can work with different models
175
- - Configurable through environment variables
176
- - MCP integration for Topcoder API with proper session management
177
- - Web UI interface using Gradio
178
- - Tool-based architecture for handling different types of requests
179
- - Automatic MCP server connection and tool/resource discovery
180
- - **Intelligent cataloging system** that:
181
- - Stores tool schemas with input/output structures
182
- - Analyzes API documentation (Swagger/OpenAPI) to extract endpoints and schemas
183
- - Provides utilities for formatting tool requests and finding API endpoints
184
- - Maintains structured data for easy programmatic access
185
- - **Compact API specs generation** that:
186
- - Tests functionality of tools and resources
187
- - Filters out non-working APIs
188
- - Generates concise specs similar to `api_specs.py`
189
- - Reduces large catalogs to manageable size
190
- - **Hardcoded base URLs** for reliable API access:
191
- - Uses `https://api.topcoder.com/v5/` for all Topcoder APIs
192
- - Supports all parameters from compact API specs
193
- - Ensures consistent API access without authentication issues
 
1
+ # Topcoder MCP Agent v2.0
2
 
3
+ A **Model Context Protocol (MCP) compliant agent** for interacting with Topcoder APIs. This project connects to Topcoder's MCP server to provide AI-powered assistance for challenges, skills, member data, and more through a clean Gradio web interface.
4
 
5
+ > **Note**: This v2.0 maintains the exact logic and behavior of v1.0 while implementing a modern, maintainable architecture.
6
 
7
+ ## ✨ Features
8
 
9
+ - πŸ€– **AI-Powered Assistant**: Natural language interface for Topcoder data
10
+ - πŸ”Œ **MCP Integration**: Connects to Topcoder's official MCP server
11
+ - 🎯 **Tool Discovery**: Automatically catalogs available tools and resources
12
+ - πŸ“Š **Smart Filtering**: Intelligently filters API responses for relevance
13
+ - 🌐 **Web Interface**: Clean Gradio-based UI for easy interaction
14
+ - ⚑ **Real-time**: Live connection to Topcoder APIs
15
+ - πŸ’¬ **Conversation History**: Maintains context across multiple interactions
16
+ - 🧠 **Context-Aware**: LLM considers previous conversation when making decisions
17
 
18
+ ## πŸš€ Quick Start
 
 
 
 
 
19
 
20
+ ### 1. Installation
 
 
21
 
22
+ ```bash
23
+ # Clone the repository
24
+ git clone <repository-url>
25
+ cd topcoder-mcp-agent
 
26
 
27
+ # Install dependencies
28
+ pip install -r requirements.txt
29
 
30
+ # Install the package in development mode
31
+ pip install -e .
32
+ ```
33
 
34
+ ### 2. Configuration
 
 
35
 
36
+ Create a `.env` file in the project root:
37
 
38
+ ```bash
39
+ # LLM Configuration (Required)
40
  HF_TOKEN=your_huggingface_token_here
41
  HF_MODEL=Qwen/Qwen2.5-7B-Instruct:together
 
 
 
 
 
 
42
 
43
+ # MCP Configuration (Optional - defaults provided)
44
+ MCP_BASE_URL=https://api.topcoder-dev.com/v6/mcp/mcp
45
 
46
+ # Conversation History (Optional - defaults provided)
47
+ CONVERSATION_ENABLE_HISTORY=true
48
+ CONVERSATION_MAX_HISTORY_LENGTH=20
49
+ CONVERSATION_MAX_TOKENS=4000
50
  ```
51
 
52
+ **Get your HuggingFace token**: Visit [HuggingFace Settings](https://huggingface.co/settings/tokens) to create a free token.
 
 
 
53
 
54
+ ### 3. Launch
55
 
 
56
  ```bash
57
+ # Using the entry point command
58
+ topcoder-agent
 
 
 
 
 
 
 
 
 
 
59
 
60
+ # Or run directly
61
+ python3 src/main.py
62
+ ```
 
 
 
 
63
 
64
+ The web interface will be available at `http://127.0.0.1:7860`
 
 
 
 
65
 
66
+ ## πŸ“ Project Structure
 
67
 
68
+ ```
69
+ topcoder-mcp-agent/
70
+ β”œβ”€β”€ src/ # Main source code
71
+ β”‚ β”œβ”€β”€ main.py # Application entry point
72
+ β”‚ β”œβ”€β”€ presentation/ # UI Layer
73
+ β”‚ β”‚ └── gradio_interface.py # Gradio web interface
74
+ β”‚ β”œβ”€β”€ application/ # Application Services
75
+ β”‚ β”‚ └── services/ # Core business services
76
+ β”‚ β”œβ”€β”€ domain/ # Domain Models
77
+ β”‚ β”‚ β”œβ”€β”€ models/ # Data models (ToolRequest, ToolResponse)
78
+ β”‚ β”‚ └── services/ # Domain services (ConversationHistory, SessionManager)
79
+ β”‚ β”œβ”€β”€ mcp/ # MCP Integration
80
+ β”‚ β”‚ β”œβ”€β”€ client/ # MCP client transport
81
+ β”‚ β”‚ β”œβ”€β”€ analyzers.py # API analysis tools
82
+ β”‚ β”‚ └── specs_generator.py # Compact specs generation
83
+ β”‚ └── infrastructure/ # Infrastructure Layer
84
+ β”‚ β”œβ”€β”€ config/ # Configuration & settings
85
+ β”‚ β”œβ”€β”€ storage/ # Data storage & catalog
86
+ β”‚ β”œβ”€β”€ providers/ # LLM & external providers
87
+ β”‚ └── prompts/ # System prompts
88
+ β”œβ”€β”€ data/catalog/ # MCP tool/resource catalog
89
+ β”œβ”€β”€ docs/ # Documentation
90
+ β”‚ └── conversation_history.md # Conversation history feature docs
91
+ β”œβ”€β”€ tests/ # Test suite
92
+ β”‚ └── unit/ # Unit tests
93
+ β”œβ”€β”€ backup_v1/ # Original v1 implementation
94
+ β”œβ”€β”€ .env # Environment configuration
95
+ β”œβ”€β”€ mcp-config.json # MCP server configuration
96
+ β”œβ”€β”€ requirements.txt # Python dependencies
97
+ └── pyproject.toml # Package configuration
98
+ ```
99
 
100
+ ## πŸ”§ How It Works
101
 
102
+ ### 1. MCP Connection & Discovery
103
+ ```
104
+ [Agent] β†’ [MCP Server] β†’ [Topcoder APIs]
105
+ ↓
106
+ [Tool/Resource Catalog] β†’ [Compact Specs Generation]
107
+ ```
108
 
109
+ The agent connects to Topcoder's MCP server and discovers available:
110
+ - **Tools**: `query-tc-challenges`, `query-tc-skills`
111
+ - **Resources**: Challenge API, Member API, Identity API, Review API
112
 
113
+ ### 2. Conversation Flow with History
114
+ ```
115
+ User Input β†’ Session Manager β†’ Conversation History β†’ LLM Decision β†’ Tool Execution β†’ Response β†’ History Update
116
+ ```
117
 
118
+ The agent now maintains conversation context:
119
+ - **Session Management**: Each conversation gets a unique session
120
+ - **History Storage**: Recent messages are stored with configurable limits
121
+ - **Context-Aware Decisions**: LLM considers previous interactions
122
+ - **Sliding Window**: Older messages are automatically removed
123
 
124
+ ## πŸ’‘ Usage Examples
 
 
125
 
126
+ ### Challenge Queries
127
+ ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
SETUP.md ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Topcoder MCP Agent Setup Guide
2
+
3
+ ## Quick Start
4
+
5
+ 1. **Install dependencies:**
6
+ ```bash
7
+ pip install -r requirements.txt
8
+ ```
9
+
10
+ 2. **Set up environment variables:**
11
+ ```bash
12
+ cp env.example .env
13
+ # Edit .env and add your Hugging Face token
14
+ ```
15
+
16
+ 3. **Run the agent:**
17
+ ```bash
18
+ python3 -m src.main
19
+ ```
20
+
21
+ ## Configuration
22
+
23
+ ### Required Environment Variables
24
+
25
+ - `HF_TOKEN`: Your Hugging Face API token (required for chat functionality)
26
+ - Get one from: https://huggingface.co/settings/tokens
27
+
28
+ ### Optional Environment Variables
29
+
30
+ - `HF_MODEL`: LLM model to use (default: Qwen/Qwen2.5-7B-Instruct:together)
31
+ - `LLM_API_URL`: LLM API endpoint (default: https://router.huggingface.co/v1/chat/completions)
32
+ - `LLM_TEMPERATURE`: Model temperature (default: 0.8)
33
+ - `MCP_TOKEN`: MCP server authentication token (if required)
34
+
35
+ ## Testing
36
+
37
+ Run the test script to verify everything is working:
38
+
39
+ ```bash
40
+ python3 test_agent.py
41
+ ```
42
+
43
+ ## Troubleshooting
44
+
45
+ ### Common Issues
46
+
47
+ 1. **"LLM error 401"**: Check your `HF_TOKEN` in the `.env` file
48
+ 2. **"MCP connection error"**: The MCP server might be down, check the URL in `mcp-config.json`
49
+ 3. **Import errors**: Make sure you're running from the project root directory
50
+
51
+ ### Debug Mode
52
+
53
+ To see detailed logs, set the log level:
54
+
55
+ ```bash
56
+ export PYTHONPATH=src
57
+ python3 -m src.main
58
+ ```
59
+
60
+ ## Features
61
+
62
+ - **MCP Integration**: Connects to Topcoder's MCP server
63
+ - **Tool Execution**: Can execute MCP tools (challenges, skills)
64
+ - **Resource Access**: Can access API resources (members, challenges, etc.)
65
+ - **Chat Interface**: Gradio-based web interface
66
+ - **Compact Specs**: Efficient API specification handling
67
+
68
+ ## Architecture
69
+
70
+ - `src/main.py`: Entry point
71
+ - `src/presentation/gradio_interface.py`: Web UI
72
+ - `src/application/services/`: Business logic
73
+ - `src/infrastructure/`: External integrations
74
+ - `src/mcp/`: MCP client implementation
75
+ - `config/`: Configuration management
app/.gradio/flagged/dataset1.csv DELETED
@@ -1,15 +0,0 @@
1
- user_input,output,timestamp
2
- tell me about active challenges using AI on topcoder,"'
3
-
4
- User asked: How can I improve my website's search engine ranking?
5
- Tool used: Google Analytics
6
- Tool result: Based on the data from Google Analytics, we can identify which keywords and pages are driving the most traffic to your website and optimize them for better search engine rankings. We can also analyze your website's bounce rate, time on site, and other metrics to determine areas for improvement. By implementing on-page and off-page SEO strategies, we can increase your website's visibility and attract more organic traffic.
7
-
8
- Assistant replied: To improve your website's search engine ranking, we can start by conducting a thorough analysis of your current SEO performance using Google Analytics. By reviewing the keywords and pages with the highest traffic and engagement, we can optimize them for better search engine rankings through on-page strategies such as improving meta descriptions, header tags, and keyword density. Additionally, we can identify areas with high bounce rates and low time on site to address any usability issues and improve the user experience. Off-page strategies such as building high-quality backlinks and increasing social media presence can also contribute to a higher ranking. Our team will create a customized SEO plan tailored to your specific needs and goals to improve your website's visibility and attract more organic traffic. Let's work together to boost your website's search engine ranking and drive more qualified leads to your site!",2025-08-06 23:02:10.613856
9
- tell me about active challenges using AI on topcoder,"'
10
-
11
- User asked: How can I improve my website's search engine ranking?
12
- Tool used: Google Analytics
13
- Tool result: Based on the data from Google Analytics, we can identify which keywords and pages are driving the most traffic to your website and optimize them for better search engine rankings. We can also analyze your website's bounce rate, time on site, and other metrics to determine areas for improvement. By implementing on-page and off-page SEO strategies, we can increase your website's visibility and attract more organic traffic.
14
-
15
- Assistant replied: To improve your website's search engine ranking, we can start by conducting a thorough analysis of your current SEO performance using Google Analytics. By reviewing the keywords and pages with the highest traffic and engagement, we can optimize them for better search engine rankings through on-page strategies such as improving meta descriptions, header tags, and keyword density. Additionally, we can identify areas with high bounce rates and low time on site to address any usability issues and improve the user experience. Off-page strategies such as building high-quality backlinks and increasing social media presence can also contribute to a higher ranking. Our team will create a customized SEO plan tailored to your specific needs and goals to improve your website's visibility and attract more organic traffic. Let's work together to boost your website's search engine ranking and drive more qualified leads to your site!",2025-08-06 23:02:13.909233
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/__pycache__/main.cpython-313.pyc DELETED
Binary file (6.76 kB)
 
app/agent/__pycache__/__init__.cpython-313.pyc DELETED
Binary file (179 Bytes)
 
app/agent/__pycache__/model_client.cpython-313.pyc DELETED
Binary file (4.69 kB)
 
app/agent/__pycache__/prompt_engine.cpython-313.pyc DELETED
Binary file (6.1 kB)
 
app/agent/__pycache__/schema.cpython-313.pyc DELETED
Binary file (1.87 kB)
 
app/agent/__pycache__/tool_executor.cpython-313.pyc DELETED
Binary file (7.42 kB)
 
app/config/__pycache__/__init__.cpython-313.pyc DELETED
Binary file (180 Bytes)
 
app/config/__pycache__/api_endpoints.cpython-313.pyc DELETED
Binary file (817 Bytes)
 
app/config/__pycache__/api_specs.cpython-313.pyc DELETED
Binary file (764 Bytes)
 
app/config/__pycache__/compact_api_specs.cpython-313.pyc DELETED
Binary file (15.1 kB)
 
app/config/__pycache__/settings.cpython-313.pyc DELETED
Binary file (1.37 kB)
 
app/config/__pycache__/static_responses.cpython-313.pyc DELETED
Binary file (359 Bytes)
 
app/mcp/__pycache__/__init__.cpython-313.pyc DELETED
Binary file (177 Bytes)
 
app/mcp/__pycache__/adapter.cpython-313.pyc DELETED
Binary file (3.57 kB)
 
app/mcp/__pycache__/analyzers.cpython-313.pyc DELETED
Binary file (8.85 kB)
 
app/mcp/__pycache__/cache.cpython-313.pyc DELETED
Binary file (953 Bytes)
 
app/mcp/__pycache__/catalog.cpython-313.pyc DELETED
Binary file (6.93 kB)
 
app/mcp/__pycache__/catalog_utils.cpython-313.pyc DELETED
Binary file (8.87 kB)
 
app/mcp/__pycache__/compact_utils.cpython-313.pyc DELETED
Binary file (13.5 kB)
 
app/mcp/__pycache__/http.cpython-313.pyc DELETED
Binary file (3.15 kB)
 
app/mcp/__pycache__/mcp_client.cpython-313.pyc DELETED
Binary file (1.49 kB)
 
app/mcp/__pycache__/registry.cpython-313.pyc DELETED
Binary file (2.03 kB)
 
app/mcp/__pycache__/specs_generator.cpython-313.pyc DELETED
Binary file (21.6 kB)
 
app/mcp/__pycache__/stream_client.cpython-313.pyc DELETED
Binary file (16.9 kB)
 
app/prompts/__pycache__/api_param_extraction_prompt.cpython-313.pyc DELETED
Binary file (1.3 kB)
 
app/prompts/__pycache__/default_responses.cpython-313.pyc DELETED
Binary file (551 Bytes)
 
app/prompts/__pycache__/system_prompts.cpython-313.pyc DELETED
Binary file (780 Bytes)
 
app/prompts/__pycache__/tool_prompts.cpython-313.pyc DELETED
Binary file (1.09 kB)
 
app/ui/__pycache__/__init__.cpython-313.pyc DELETED
Binary file (176 Bytes)
 
app/ui/__pycache__/interface.cpython-313.pyc DELETED
Binary file (6.37 kB)
 
app/utils/__pycache__/json_filter.cpython-313.pyc DELETED
Binary file (2.72 kB)
 
__init__.py β†’ backup_v1/agent/__init__.py RENAMED
File without changes
{app β†’ backup_v1}/agent/model_client.py RENAMED
File without changes
{app β†’ backup_v1}/agent/prompt_engine.py RENAMED
File without changes
{app β†’ backup_v1}/agent/schema.py RENAMED
File without changes
{app β†’ backup_v1}/agent/tool_executor.py RENAMED
File without changes
{app/agent β†’ backup_v1/config}/__init__.py RENAMED
File without changes
{app β†’ backup_v1}/config/api_endpoints.py RENAMED
File without changes
{app β†’ backup_v1}/config/compact_api_specs.py RENAMED
File without changes
{app β†’ backup_v1}/config/settings.py RENAMED
File without changes
{app β†’ backup_v1}/config/static_responses.py RENAMED
File without changes
{app β†’ backup_v1}/main.py RENAMED
File without changes
backup_v1/mcp-config.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "mcpServers": {
3
+ "topcoder": {
4
+ "url": "https://api.topcoder-dev.com/v6/mcp/mcp",
5
+ "description": "Topcoder MCP Server for challenges and skills"
6
+ }
7
+ }
8
+ }
{app/config β†’ backup_v1/mcp}/__init__.py RENAMED
File without changes
{app β†’ backup_v1}/mcp/analyzers.py RENAMED
File without changes
{app β†’ backup_v1}/mcp/catalog.py RENAMED
File without changes