File size: 2,342 Bytes
252b40c
dbdd109
252b40c
 
 
 
481cde4
252b40c
 
e30962b
546187f
 
5ac086f
252b40c
 
e30962b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
---
title: TDAgentTools
emoji: 💬
colorFrom: yellow
colorTo: purple
sdk: gradio
sdk_version: 5.32.1
app_file: app.py
pinned: false
license: apache-2.0
tags:
 - mcp-server-track
short_description: Cybersecurity MCP tools to enhance threat insights
---

# TDA Agent Tools

# Development setup

To start developing you need the following tools:

 * [uv](https://docs.astral.sh/uv/)

To start, sync all the dependencies with `uv sync --all-groups`.
Then, install the pre-commit hooks (`uv run pre-commit install`) to
ensure that future commits comply with the bare minimum to keep
code _readable_.

Once `uv` has installed all the dependencies, install the `pre-commit`
hooks to run linting and requirement files update, etc., before creating
new commits:

```bash
uv run pre-commit install
```

# Adding new tools

For the sake of clarity, we organize tools under the directory
`tdagent/tools/`, and then add them to the `app.py` list of
interfaces.

As an example, let's create a tool that adds up two numbers. First,
we create a new file `tdagent/tools/calc_tool.py` with the following
content:

```Python
import gradio as gr


def add_numbers(num1: float, num2: str) -> float:
    """Compute the addition of two numbers `num1 + num2`.

    Args:
        num1: First number to add.
        num2: Second number to add.

    Returns:
        The result of computing `num1 + num2`.
    """
    return num1 + num2


gr_add_numbers = gr.Interface(
    fn=add_numbers,
    inputs=["number", "number"],
    outputs="number",
    title="Add two numbers",
    description="Compute the addition of two numbers",
)
```

Naming the file `calc_tool.py` is convenient as it let us add
additional tools to calculate operations inside the same Python
module.

Then, we modify the `app.py` file to include our new tool.

```Python
import gradio as gr

from tdagent.tools.get_url_content import gr_get_url_http_content
...  # Other tools already present before
from tdagent.tools.calc_tool import gr_add_numbers


gr_app = gr.TabbedInterface(
    [
        gr_get_url_http_content,
        ...,  # Other tools already present before
        gr_add_numbers
    ],
)

if __name__ == "__main__":
    gr_app.launch(mcp_server=True)
```

In future updates we might change the `app.py` to automatically
include any `gr.Interface`, but for now this works just fine.