upload-file
Upload files to OpenAI Assistants for processing and analysis, enabling document-based interactions through the MCP server.
Instructions
Upload a file for use by assistants
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | The local path to the file to upload |
Implementation Reference
- src/mcp_server_openai/llm.py:87-94 (handler)Core handler implementation that opens the local file and uploads it to OpenAI using the AsyncOpenAI client with purpose='assistants'.async def upload_file(self, file_path: str): try: with open(file_path, "rb") as file: response = await self.client.files.create(file=file, purpose="assistants") return response except Exception as e: logger.error(f"Failed to upload file {file_path}: {str(e)}") raise
- src/mcp_server_openai/server.py:101-111 (registration)Registers the 'upload-file' tool in the MCP server's list_tools handler, including its schema for input validation.types.Tool( name="upload-file", description="Upload a file for use by assistants", inputSchema={ "type": "object", "properties": { "file_path": {"type": "string", "description": "The local path to the file to upload"} }, "required": ["file_path"] } ),
- src/mcp_server_openai/server.py:193-195 (handler)Dispatch logic in the server's call_tool handler that invokes the LLMConnector's upload_file method and formats the response.elif name == "upload-file": response = await connector.upload_file(arguments["file_path"]) return [types.TextContent(type="text", text=f"File uploaded: {response.filename}, ID: {response.id}")]