]> apps.delaporte.us Git - matrix-shop-bot.git/blob - skill.py
Add CORS support
[matrix-shop-bot.git] / skill.py
1 from fastmcp import FastMCP
2 from matrix_shop_bot.db import Data
3 import os
4 import uvicorn
5
6 from starlette.middleware import Middleware
7 from starlette.middleware.cors import CORSMiddleware
8 import uvicorn
9
10
11 MY_IP=os.environ.get('MY_IP')
12 mcp = FastMCP("Shop Bot")
13
14 @mcp.tool
15 def add_item(name: str) -> str:
16 return '\n'.join(Data().add_item(name))
17
18 # Define custom middleware
19 custom_middleware = [
20 Middleware(CORSMiddleware, allow_origins=["*"],
21 allow_methods=["*"],
22 allow_headers=["*"],),
23 ]
24
25 if __name__ == "__main__":
26 http_app = mcp.http_app(transport="streamable-http",path="/",middleware=custom_middleware)
27 uvicorn.run(http_app, host=MY_IP, port=9000)
28
29
30
31 #@mcp.tool
32 #def buy(items:str) -> 'list[str]':
33 # return Data().purchase_items(items)
34 #
35 #@mcp.tool
36 #def list_bought(store:str) -> 'list[str]':
37 # return Data().list_purchases(store)
38 #
39 #@mcp.tool
40 #def clear(store_name: str, clear_all:bool=False) -> 'list[str]':
41 # return Data().clear_list(store_name, clear_all)
42 #
43 #
44 #@mcp.tool
45 #def shop_at(store_name:str) -> 'list[str]':
46 # '''Select store to shop at'''
47 # return Data().get_shopping_list(store_name)
48 #
49 #
50 #@mcp.tool
51 #def list() -> 'list[str]':
52 # '''Use previous store'''
53 # return Data().get_last_shopping_list()
54 #
55 #
56 #@mcp.tool
57 #def list_stores() -> 'list[str]':
58 # return Data().get_stores()
59 #
60 #
61 #@mcp.tool
62 #def list_purchases(store: str) -> 'list[str]':
63 # return Data().list_purchases(store)
64
65 # if __name__ == "__main__":
66 # mcp.run(transport="http", host=MY_IP, port=9000)